Previous Example-|-Next Example-|-Return to Chapter Listing

Example 7.10:
Working with Multiple Functions


This page uses a function, Percentage(sNum, sPerc), as in example 7-8 but this time this is called from a function, GetNumbers which gets the values from text boxes.
Enter a number:
Enter the percentage you want:



These are the scripts we used. First, in the HEAD: <SCRIPT LANGUAGE="JavaScript"> <!-- function GetNumbers(form) { var sNumber = form.txtNumber.value var sPercentage = form.txtPercent.value form.txtResult.value= Percentage(sNumber, sPercentage) } function Percentage(sNum, sPerc) { var nResult = sNum * (sPerc/100) return nResult } //--> </SCRIPT> Later in the Web page the function is called from this form: <FORM> Enter a number: <INPUT TYPE="text" NAME="txtNumber" SIZE=6><BR> Enter the percentage you want: <INPUT TYPE="text" NAME="txtPercent" SIZE=6><P> <INPUT TYPE="button" VALUE="Result" onclick="GetNumbers(this.form)"> <INPUT TYPE="text" NAME="txtResult" SIZE=10> </FORM>
Previous Example-|-Next Example-|-Return to Chapter Listing