Wednesday, March 9, 2011

How to display date and year on a web page using JavaScript - Project level Basic"

Last week, I had requested a project for students to display the date using the date object in JavaScript, on an order details page. Here is the solution to the project:

In the .js file or the head script stream, enter the following code-

1> orddate = new Date();
2> dispdate = orddate.getMonth() + 1 + "-" + orddate.getDate() + "-" + orddate.getYear();

Further in the body stream of the html file the date can be displayed using the DOM innerHTML =+ dispdate or using the document.write method.

Addition: With the document.write method a table is being created displaying the order date. This can be in the init function of the js file. The code is as follows

  1. document.write('<html><body><table align="top" cellpadding="4" cellspacing="7">');
  2. document.write('<tr><td><font color="#ffffff" size="4" face="verdana">' + "The Order Date is: " + dispdate + '</font></td></tr>');
  3. document.write('<tr><td><font color="#ffffff" size="4" face="verdana">' + "The Delivery Date is 3 days from the order date" + '</font></td></tr>');
  4. document.write('</table></body></html>');
For more information visit abco technology training at ABCO Technology


Check Us Out We Are All Over The Web!!






Check Out Our Website

1 comment:

Unknown said...

I try your code but I´m not able to display the date inside the table.