ParseInt() and ParseFloat()  

What's the number?
Select a string
Integer
Float


ParseInt() and ParseFloat() are internal JavaScript functions which search for numbers (integers and floating point) in text strings, such as data returned from forms.

The default input type for ParseInt() is decimal (base 10). If the number begins in "0", it is assumed to be octal (base 8). If it begins in "0x", it is assumed to be hexadecimal (base 16). The code NaN ("Not a Number") is returned for strings which cannot be converted to numbers.

This page also shows an example of reading the input from <SELECT> form controls. The number of the selected item is in the selectedIndex property of the control. Once this is known, the value can be read from the control's array of options with options[i].value, where i is the number of the selected item. (As usual in JavaScript, the array is numbered from 0.)

Code in the page header
<script language="JavaScript" type="text/javascript">
<!--
function FindNums(paramform) {
  var i = paramform.cmbInput.selectedIndex
  var vInput = paramform.cmbInput.options[i].value

  paramform.txtIntOutput.value = parseInt(vInput) ;
  paramform.txtFloatOutput.value = parseFloat(vInput) ;
} 
//-->
</script>

The form

<FORM NAME="ParseIntForm">
<table summary="" cellpadding=5 cellspacing=0 border=2>
<tr>

<td align=right valign=top>
<b>Select a string</b>
</td><td align=left colspan=2>
<SELECT NAME="cmbInput" SIZE=5>
<OPTION SELECTED VALUE="1234.56"> 1234.56 (a decimal number)
<OPTION VALUE="046"> 046 (an octal number)
<OPTION VALUE="0xFF"> 0xFF (a hexadecimal number)
<OPTION VALUE="Red 4 Dog"> Red 4 Dog (a string)
<OPTION VALUE="Brown fox"> Brown fox (a string)
</SELECT>
</td>

</tr><tr>

<td align=right valign=top rowspan=2>
<INPUT TYPE="button" VALUE="Find numbers!" 
onclick="FindNums(document.ParseIntForm)"></td>

<td align=right>Integer</td>
<td align=left><INPUT TYPE="text" NAME="txtIntOutput" SIZE=20></td>

</tr><tr>

<td align=right>Float</td>
<td align=left><INPUT TYPE="text" NAME="txtFloatOutput" SIZE=20></td>

</tr>
</table>
</FORM>