Javascript Functions
Functions Calling Functions
The advantage of functions is that they perform
actions upon request with different pieces of
data.
If a function prints a string, it will print a
string any time we call it and give it a string
to process.
In the following example we do something more:
one function calls another.
showDefault(x) puts the value of a variable
in a readonly form field for display.
setDefault() sets the variable to the value of
another form field upon clicking the button
"inputButton"; then it calls the function
to display the new value in that field.
The input value of a form field is thus passed to
a function, and from there to another one.
Result:
The code:
<script type="text/javascript">
<!--
var displayString = "[default]";
function showDefault(x)
{
// set field value to variable
document.forms.form1.output1.value = x;
return true;
}
function setDefault(x)
{
// set the variable to new value
displayString = x;
//set the input field to blank
document.forms.form1.input1.value = "";
//call the display function
showDefault(displayString);
}
// -->
</script>