<%response.buffer=true%> <% Response.Expires = 0 %> JS Examples

Example Files

Below are links to example files that we have built in class.  If You click on the file name, you can see an example of the file in action.  View the HTML SOURCE to see how the code operates.

File Name Function Notes
Demonstrates use of the Date() object. Shows current year as part of page copyright.

Place in a JS include file and keep all your pages up to date.

Uses Date() object in a different way. Shows date in mm/dd/yyyy format. Example of conditional if/then syntax.
Image/color/messages change based on hour of day. (Harnesses system clock) Swap out multiple variables in if/else statement and customize page HTML with document.write.
Change the body color (of entire HTML document). Document is not available to change until entire page has been loaded, hence the use of onload(). Demos onload() event handler. bodycolor3.htm uses a custom function, called after the page is loaded.
Switches page content based on date (1-31, etc). Rotates content based on modulus. Demos switch statement, modulus operator.
Uses window.open to popup a page into a new window. Demos custom functions to vary window size, document location via anchor tags.
Demonstrates properties of the navigator object, and for/in looping example. Knowing the browser of the user can allow custom styles, etc.
randomQuotes.htm Generates random quotes from an array built in JS. Uses an array as a data source.
huey.htm A simple array example. A basis for next example (SplitNephews).
SplitNephews.htm Splits a comma separated form element value in an array, and prints to the screen. Shows use of split function, and DOM manipulation via innerHTML.
Uses the onerror event handler to perform cross browser error reporting View this document to create a cross browser error handling include file: JavaScript Error Handling
Demonstrates various ways to create a "rollover" image effect.

Rollover effects usually use the onmouseover and onmouseout event handlers.

As long as your images are pre-loaded, how you roll the images is up to you!

Use an include file to load custom CSS stylesheets for specific browsers.

The code can be adapted to just about any combination of browsers.


Try the link with different browsers. Each of the identified browsers calls a separate stylesheet, which changes the color of the page text.

The code relies on a 'default' CSS file being selected, which is the fallback if there is not a match for a specific browser: loadStyle()

An example of form validation workups we built in class.

Check the handouts: Validate Text, Validate Radio and Validate Select .


Print this Page Back To Top

2000- <%=year(date)%> newMANIC INC, All rights reserved