Javascript Functions
Passing Parameters to Functions
Functions can be given one or more pieces of data,
parameters, to use in their code. Parameters are included
in the function call in parentheses
(see the onload event handler).
Parameters must be included in the function definition.
There they may have a name different from the function
call, but the names defined in the function definition
must be used within the function.
In the following example, the variable 'displayString'
of the function call becomes variable 'x' in the function;
The onload
event handler passes the variable 'displayString',
which has been created when the script above was loaded
to the function showMe( )
which has been stored in
memory by the same script.
The result:
The code:
<script type="text/javascript">
<!--
var displayString = "[variable]";
function showMe(x)
{
document.forms.form1.output1.value = x;
return true;
}
// -->
</script>