![]() |
The JavaScripts on this page are a bit more complex than those on the first page. We highly recommend you test each script on a test page before deploying on a production page. |
Simply cut-and-paste the blue code listings and paste them into your preferred editor and make the suggested changes (usually the green parts) as we discuss certain JavaScript features. | |
Easy JavaScript Volume 2 Part 1 Drop-Down Menu Link List You can save a lot of web page space using a drop-down menu list if you have numerous links for viewer selection. If you don't know how to set it up, simply insert a URL where the list value would normally be in the code below. Then you create a function to work with that URL. Then you can create an active drop down menu list, like the one shown at the top of this page. This code is embedded within the <HEAD> section of the page document
Now we create a drop-down menu list and place it within the <BODY> section where needed to be displayed.
A working example of this code is shown below: |
|
Easy JavaScript Volume 2 Part 2 Automatic Current Date Display With JavaScript you can have the current date automatically displayed where ever you would like it to appear on your web page. First Step: We may now use the created variables in "write statements" within the <BODY> section of document. You may also reference the giveDate() function, as seen below:
A working example of this code shown below: |
|
Easy JavaScript Volume 2 Part 3 Randomized Message Arrays To keep your web site fresh with new content it helps to have fresh text content change from viewer entry to re-entry, etc. The following JavaScript displays a (seemingly) random phrase on a page each time it is loaded. Works best with version 4.x browser generation. First Step: We create a function for making message arrays, we then create each individual message array, then we build the random-number generator to sort them by rotation load. You may copy-and-paste the following code into the <HEAD> section of your document:
We now must ensure that the parameters of the random number generator are sufficiently set to cover all the elements=messages[0] of your array. For example, the number 5 above is necessary to cope with the 4 elements of our messages array. So if we had ten elements, the number would have to be 11 to effectively randomize each message array. Copy-and-Paste the following code anywhere in the <BODY> section you want array message visible:
A working example is visibly shown below. Refresh Page for new array message: Our message of the day is: |
|
Easy JavaScript Volume 2 Part 4 Remote JavaScript Source Code There may be instances where you want your javascripts to be run remotely for security reasons, or because you want the same script to power several files without having to maintain the script in several files. The following script will allow you to run a javascript located in it's own file in your directory allowing you to effectively call the javascript function without it visibly seen on page. This is a sure fire way to get around the Search Engines dislikes for meeting javascript codes and inability to read some navigation written in the script code.
The actual script does not need to contain the opening and closing script tags, just the code as you'd write it up. Just save it as a normal text file with a .js extension to it (GPU will work with this particular format). For example:
|
|
Easy JavaScript Volume 2 Part 5 Daily Currency Exchange Rate Converter Currency Converter Provided By: University of Alberta Currency Converter
To use the code generator, please provide a dollar value in the box, then click the Generate Code! button.
For example, running "390" through the code generator and pasting the code into a file would
Just click on any of the currencies listed and you will see the same-day exchange rate results. |
Some examples shown are courtesy of internet.com | |