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

Example 7.13:
Built-in Functions--parseFloat


This page uses a built-in function, parseFloat(form.txtNum.value), to return a floating-point number. Type a number--try typing a decimal number into the first text box, then click on the button to see the result. You can type in - to make your number negative or you can use "e" to represent exponential values:
Type a number:



These are the scripts we used. First, in the HEAD: <SCRIPT LANGUAGE="JavaScript"> <!-- function GetFloat(form) { form.txtFloat.value= parseFloat(form.txtNum.value) } //--> </SCRIPT> Later in the Web page the function is called from this form: <FORM> Type a number: <INPUT TYPE="text" NAME="txtNum" SIZE=12><P> <INPUT TYPE="button" VALUE="Result" onclick="GetFloat(this.form)"> <INPUT TYPE="text" NAME="txtFloat" SIZE=30> </FORM>
Previous Example-|-Next Example-|-Return to Chapter Listing