Back
The bgColor property catching multiple values with arguments

What we are doing here is changing the 'bgColor' property of the document object using arguments. This is the great thing about arguments - we can use only one function while using multiple values of a variable.

function changeBackground(myColor) { //declare argument

document.bgColor = myColor // show where argument is to be used

}


It is from within the event handlers that we tell the script the value of the color argument.

<form>
<input type="button" onClick="changeBackground('blue')" value="blue">
<input type="button" onClick="changeBackground('yellow')" value="yellow">
<input type="button" onClick="changeBackground('green')" value="green">
</form>


This also works with the "onMouseOver/onMouseOut" event handlers.

View the Source