Previous Example-|-Next Chapter's Examples-|-Return to Chapter Listing

Example 7.19:
Passing Parameters to a Function Object

[This example works with Netscape Navigator 3. It will not work with Internet Explorer 3.]

Type a number into the text box. Clicking the button calls a function which passes a number to a function object. The object divides the number in two, then passes it back:


In the HEAD we have this script: <SCRIPT LANGUAGE="JAVASCRIPT"> <!-- var FuncObj = new Function("x","x=x/2;return(x)") function Func1() { var x= document.Form01.txtInteger.value x = FuncObj(x); alert(x); } //--> </SCRIPT> In the BODY of the page we have this form: <FORM NAME="Form01"> <INPUT TYPE="text" NAME="txtInteger" SIZE=20><P> <INPUT TYPE="button" VALUE="Run the functions" name="cmb1" onClick="Func1()"> </FORM>
Previous Example-|-Next Chapter's Example-|-Return to Chapter Listing