Use these to jump around or read it all
The Concept
The Script
The Script’s Effect
Deconstructing the Script
What You’ve Learned
Your Assignment
![]()
The Concept
The purpose of this example is to introduce you to forms and JavaScript. This script uses a form to allow you to choose a background color, either blue or pink. Notice that the color selection is done through form buttons.
Forms always begin with
. No surprises here, just good old HTML!The Script
The example below will again show the full HTML document:
Select a Background Color |
|---|
The Script’s Effect
F
ollow
to see the script in action
Deconstructing the Script
- Time for a new term! A literal is a VALUE that does not change. It can be a number, a name, or any random series of both. Just remember that a literal is solid. It cannot be altered.
- Time for another new term! A string is any run of letters or numbers within single or double quotes. Thus this section from the script:
__ATLAS_CODE_BLOCK__0__
…is defining the literal string “lightblue.” Still with me? Good. - Here’s the script and the input items again:
- __ATLAS_TABLE_BLOCK__1__
- __ATLAS_TABLE_BLOCK__2__
- Notice we are passing a literal string, ‘lightblue’ or ‘pink’, to the function, newcolor(). The string is surrounded by single quotes because the function name is surrounded by double quotes.
- When a button is clicked, the string in the parentheses
(either ‘pink’ for ‘lightblue’) is passed to the function newcolor(). - Basically, the function is waiting until it is given the information it needs to perform. Remember that in all functions up until this point, the parentheses were empty. The function had all the parts it needed. Here it does not and it won’t until someone
clicks on a button. That button contains the same function, only this time the function does have the data it needs, a color command.
In this script that color command is being passed onto two items in the