Tuesday, December 25, 2012

Date Display

Date Function

This post illustrate as how to display the current date on a button click.The date format that I have used in the below example is dd/mm/yyyy. we can imply different formats.

1. Add the below code in the body section of the HTML file.

<input type="text" id="dis" /><br />

<input type="button" value="Display Date" onclick="display()" />

2. Add the below script in the .js file or you could implement the script in the head section of the HTML file.


function display(){
var x="You have clicked";
var d=new Date();
var date=d.getDate();
var month=d.getMonth();
month++;
var year=d.getFullYear();
document.getElementById("dis").value=date+"/"+month+"/"+year;
}

Hope this post was informative. Will get back with more posts shortly.







Informative Javascript

No comments:

Post a Comment