0

I have searched through jQuery's docs, and here and here and here but cannot seem to find why this does not work. I have this in a GAS html file:

<!DOCTYPE html>
  <html>
  <head>
    <base target="_top">
  </head>
  <body>
 <form>
 <p>
    Name:<input type="text" name="firstname"><br> 
    Start Date:<input type="date" id="startDate" name="startDate">
    time:<input type="time" name="startTime"><br>
    End Date:<input type="date" id="endDate" name="endDate">
    time:<input type="time" name="endTime"><br>
    <input value="Process" type="submit">
 </p>
</form>
</body>
 <?!= include('stylesheet'); ?>
 <?!= include('javascript'); ?> 
</html>

and this in a javascript.html file as well:

<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jqueryui.min.js">

$(function() { //meant to run on load
   $("#startDate").datepicker(
    {
  defaultDate: +14 //14 days from now
    }
  );
});
</script>

it works if I add a default date in the input tag for startDate, but I cannot figure out why my default date will not load. Ideas?

Community
  • 1
  • 1
  • What doesn't work? `+14 === 14`, maybe you want `'+14'`? – Musa Jul 23 '16 at 22:11
  • I have tested adding anything to this line, e.g. `defaultDate: '2016-08-01'` with no result. – Michael Ludden Jul 24 '16 at 02:38
  • It did work, but not the way I thought. After changing the `type` to `text` and using the following, I am setting the date. I thought the defaultDate also did this, but now I know. `` – Michael Ludden Jul 24 '16 at 16:37

1 Answers1

1

I believe your JavaScript code isn't running because you aren't closing and opening the <script> tags, try this in your javascript.html file:

<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jqueryui.min.js"></script>
<script>
$(function() { //meant to run on load
   alert("It's running :D");

   $("#startDate").datepicker(
    {
     defaultDate: +2
    }
  );
});
</script>

Also, don't forget to include the jQuery CDN:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
ocordova
  • 1,788
  • 2
  • 13
  • 20