The following script will display date and time:
<script>
function displaydate()
{
document.getElementById("s").innerHTML=Date();
}
</script>
In the html page, you can add this code inside the html code. If you want add a button, by clicking that button it will display the current date and time, you can use the id. Here, i mentioned getElementById ("s"). Same way you can use whatever variable in that place.
<p id="s"></p>
<button type="button" onclick="displayDate()">Display Date</button>
Try this out. You will get the result.
Post by
newWorld
<script>
function displaydate()
{
document.getElementById("s").innerHTML=Date();
}
</script>
In the html page, you can add this code inside the html code. If you want add a button, by clicking that button it will display the current date and time, you can use the id. Here, i mentioned getElementById ("s"). Same way you can use whatever variable in that place.
<p id="s"></p>
<button type="button" onclick="displayDate()">Display Date</button>
Try this out. You will get the result.
Post by
newWorld
No comments:
Post a Comment