Some JavaScript examples

These are examples of what you can do with JavaScript. To look at JavaScript source, please do 'view source'.
SourceResult
Common code:
<SCRIPT>
// preload images, which we'll use
image_empty = new Image();
image_empty.src = 'images/cart_empty.gif';

image_full = new Image();
image_full.src = 'images/cart_full.gif';

// set cart image (first image on this document)
function change_image(ind, img) {
  window.document.images[ind].src = img;
}
</SCRIPT>
 
Change images:
  <INPUT TYPE=BUTTON NAME=change_image_empty VALUE="Fill Cart"
       OnClick="change_image(0, 'images/cart_full.gif');">
  <INPUT TYPE=BUTTON NAME=change_image_empty VALUE="Empty Cart"
       OnClick="change_image(0, 'images/cart_empty.gif');">
  <IMG SRC="images/cart_empty.gif">

Mouse rollover:
<A HREF="javascript:void(null)"
  onMouseOver="change_image(1, 'images/cart_full.gif')"
  onMouseOut="change_image(1, 'images/cart_empty.gif')">
  <IMG SRC="images/cart_empty.gif" BORDER=0></A>
Form verification:
<SCRIPT>
function check_me (form) {
  if (form.exmpl_text.value != '1234') {
    alert("Please... Enter '1234' in the text field!");
    return(false);
  }
  if (!form.exmpl_check.checked) {
    alert("I've also asked to check the checkbox!");
    return(false);
  }
  alert("Wow, You've done this! Thanks!");
  return(true);
}
</SCRIPT>
  <TABLE>
  <TR>
  <TD> Please enter '1234' in this field:</TD>
  <TD> <INPUT TYPE=TEXT NAME=exmpl_text SIZE=5></TD>
  </TR>
  <TR>
  <TD> Check this box:</TD>
  <TD> <INPUT TYPE=CHECKBOX NAME=exmpl_check></TD>
  </TR>
  <TR>
  <TD> And press this button to verify</TD>
  <TD> <INPUT TYPE=BUTTON NAME=exmpl_button
        VALUE="Check me!" OnClick="check_me(this.form)"></TD>
  </TR>
  </TABLE>
Please enter '1234' in this field:
Check this box:
And press this button to verify

Advanced example: JavaScript Tetris