This page has a series of Java Script examples. The list starts with the easiest and works up to ones that are moderately complex. Be sure you understand what the example is doing before you add it to your HTML. Its not possible to cover everything you need to know about JavaScript in a class session. But here are some of the basics.
In this example file I have put together a series of useful functions that you may invoke in response to events or just to insert information on your page. To use these functions you need to copy the JavaScript contained in the header area of this file into the header area of your html file. Copy everything between and including the <SCRIPT> and the </SCRIPT> tags.
1) Display the last modification date of the document.
<Script TYPE="text/javascript">
document.write(document.lastModified); </script>
2) Display today's date.
<script
TYPE="text/javascript">
var today = new Date();
document.write(today.toLocaleString()+" ");
</script>
3) Display just the time.
<script
TYPE="text/javascript">
var today = new Date();
var mins = "";
if (today.getMinutes() >= 10)
mins=today.getMinutes();
else
mins="0" + today.getMinutes();
document.write(today.getHours()+ ":" + mins +" ");
</script>
4) Display just the date.
<script
TYPE="text/javascript">
var today = new Date();
document.write((today.getMonth()+1) + "/" +
today.getDate() + "/"
+ today.getYear() +" ");
</script>
Print - You can use a button control and add java script to invoke the document.print() method, e.g.
<button
onclick="window.print()">Print</Button>
Forward and back buttons : Again, use a button control and
associate javascript with the onclick. Use window.history.back()
or
window.history.forward(). e.g.
<button onclick="
window.history.back()">Back</Button> <button
onclick=" window.history.forward()">Forward</Button>