In order to call the function on page loading just simply call the function in the script section. Use inner HTML to display. Make the code easy and simple.
Here is the script:
function printdate() { document.getElementById("dat").innerHTML = Date(); } printdate(); //calling date
You can also write the function like this:
function printdate() { return new Date(); } document.getElementById("dat").innerHTML =printdate();
The HTML section:
<div> <p id="dat"></p> </div>
This will help you:
This link will help you to create date format
This snippet shows the date:
<html> <head> <!-- Happy New Years Author: Professor Myron Wilson Date: 8/1/2006 Filename: happynewyears.htm Supporting files: e.jpg, library.js, newyearseve.gif, styles.css --> <title>North Pole Novelties</title> <link href="styles.css" rel="stylesheet" type="text/css" /> <!-- Add library.js below --> <link rel="stylesheet" type="text/css" href="Bootstrap/css/bootstrap.css"> </head> <body> <table id="npn" cellpadding="5" cellspacing="0"> <tr> <!-- Company Hyperlinks --> <td id="links" rowspan="4" valign="top"> <a href="#">The New Year's Event Agenda</a> <a href="#"></a> <a href="#">New Year's Eve Happy Hour</a> <a href="#">New Year's Eve Concert</a> <a href="#">New Year's Eve Party</a> <a href="#">New Year's Day Brunch</a> </td> <!-- Days until New Year's Eve -->