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
- document.write('<html><body><table align="top" cellpadding="4" cellspacing="7">');
- document.write('<tr><td><font color="#ffffff" size="4" face="verdana">' + "The Order Date is: " + dispdate + '</font></td></tr>');
- document.write('<tr><td><font color="#ffffff" size="4" face="verdana">' + "The Delivery Date is 3 days from the order date" + '</font></td></tr>');
- document.write('</table></body></html>');