Michael Ludden
Michael Ludden

Reputation: 9

How to use HTMLService in GAS to add default date to jQuery datepicker?

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?

Upvotes: 0

Views: 225

Answers (1)

user3075569
user3075569

Reputation:

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>

Upvotes: 1

Related Questions