|
Parameters are pieces of information, or variables, that are sent
to the function when the function is called; parameters make functions
far more useful.
An example of where parameters would be used is in the image swap
function. When the image is rolled over by the user, the function
is called At the same time two pieces of information, or parameters,
are sent to the function. These are the image name and the image
source.
The function has to be told how many, if any, parameters it will be receiving. This is done by putting the parameter names in brackets after the function name
The parameters can then be treated as variables throughout the function.
The following script sends different parameters to the 'passParam' function depending on which button is clicked.
function passParam(message)
{
alert(message)
}
<form action="#">
<input type="button" value="Bill Gates" onclick="passParam
»('If you can’t make it good, at least make it look good.')" >
<input type="button" value="Tim Berners-Lee" onclick="passParam
»('What is a Web year now, about three months?')" >
<input type="button" value="Charles Babbage" onclick="passParam
»('Pray, Mr. Babbage, if you put into the machine wrong figures,
»will the right answers come out?')" >
</form>
Click on the buttons to see the script in action
|