JavaScript Primers #17 | HTML Goodies

JavaScript Primers #17

Written By
Joe Burns
Joe Burns
Jan 4, 2005
2 minute read

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

and end with
. No surprises here, just good old HTML!



The Script

The example below will again show the full HTML document:






Select a Background Color



onClick="newcolor('lightblue')">
onClick="newcolor('pink')">






The Script’s Effect

F

ollow

this link

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
HTML Goodies Logo

The original home of HTML tutorials. HTMLGoodies is a website dedicated to publishing tutorials that cover every aspect of being a web developer. We cover programming and web development tutorials on languages and technologies such as HTML, JavaScript, and CSS. In addition, our articles cover web frameworks like Angular and React.JS, as well as popular Content Management Systems (CMS) that include WordPress, Drupal, and Joomla. Website development platforms like Shopify, Squarespace, and Wix are also featured. Topics related to solid web design and Internet Marketing also find a home on HTMLGoodies, as we discuss UX/UI Design, Search Engine Optimization (SEO), and web dev best practices.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.