function changecolor(code) {
    document.bgColor = code
}

This page is an excellent example of one function being used by several buttons in the same document. Our function is calledchangecolor(code). It has only one line:

document.bgColor=code

You probably guessed thatbgColorstands for background color. If I typedocument.bgColor="red"the background will turn red. By writing the commanddocument.bgColor=codeI am allowing myself to define the variablecodeas any color I want.

Later, in the form. I define a button with the command:

onClick="changecolor('green')"

onClick="changecolor('green')"is telling the program 2 things:

  1. Run the funtion namedchangecolor(code)
  2. code='green'

results matching ""

    No results matching ""