Javascript Examples
<title>Hands-on JavaScript</title>
<! -- Hide JavaScript from non-compatible browsers>
<script language=JavaScript>

function first() {
  alert("Some text");
}

function second(text) {
  alert(text)
}

function third() {
 if (confirm("Can I continue?")) {
     alert ("Thanks, let's move on!");
  } else {
     alert ("OK, I'll just sit here and twiddle my thumbs.");
  }
}

function fourth(userName) {
 if (confirm("Can I continue, " + userName + "?")) {
     alert ("Thanks, let's move on!");
  } else {
     alert ("OK, I'll just sit here and twiddle my thumbs.");
  }
}

function getName () {
  userName = prompt ("\nWhat is your name?", "Name goes here");
}

function fifth() {
  if (document.forms[0].answer.value == "4" || document.forms[0].answer.value.toUpperCase() == "FOUR") {
    document.forms[0].answer.value = "Right!"
  } else {
    alert("Wrong");
  }
}

function sixth() {
  if (document.forms[0].answer.value.toUpperCase().indexOf("FOUR") != "-1") {
	    document.forms[0].answer.value = "Right!"
  } else {
    alert("Wrong");
  }
}

function seventh() {
  win = window.open("","hello","width=150,height=150");
  win.document.open();
  win.document.write("<html><body bgcolor = #FFFFFF>");
  win.document.write("Hello there, " + document.forms[0].who.value + "!");
  win.document.close();
}

</script>
<!-- end hiding -->
</head>

Here are some JavaScript examples<p>
<FORM>
Your name:<br>
<input type=text name=who><p>
What's 2 plus 2?<br>
<input type=text name=answer><p>
    </FORM>
    
<a href = "javascript:first()">Pop up a message</a><br>
<a href = "javascript:second('Here is some text')">Pop up a message again</a><br>
<a href = "javascript:third()">Can I continue?</a><br>
<a href = "javascript:fourth('Johnnie')">Can I continue - include name</a><br>
<a href = "javascript:fourth(document.forms[0].who.value)">Get user's name from form</a><br>
<a href = "javascript:fifth()">See if answer is correct</a><br>
<a href = "javascript:sixth()">Answer anywhere in response?</a><br>
<a href = "javascript:seventh()">Open a new window</a>
</BODY></HTML>