Putting today’s date on the form using javascript

Use the following code to put the date in the form.

<input type="text" id="todaydate" size="15" ></font></p>
 <script type="text/javascript" >
  var today = new Date();
 var dd = today.getDate();
 var mm = today.getMonth()+1; //January is 0!
 var yyyy = today.getFullYear();
if(dd<10) {
 dd='0'+dd
 }
if(mm<10) {
 mm='0'+mm
 } 
 today = yyyy+'-'+mm+'-'+dd;
 var element = document.getElementById("todaydate");
 element.value = today;
 </script>

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s