Numbers Only: Jumping at the Decimal PointIn the previous page we showed how to restrict a field to just numbers. In this field we show how to use two fields to split the number on the decimal place. Unfortunately, JavaScript currently lacks the properties needed to restrict decimal places within a single field. However, we can split the data into two fields -- numbers before the decimal and numbers after. When the user hits the decimal point, the cursor jumps from one field to the next. In the second field we use theMAXLENGTH
First, copy the script from the
previous page into the
<FORM ACTION="../cgi-bin/mycgi.pl" METHOD=POST> price: <INPUT NAME="dollar" SIZE=5 onKeyPress="return numbersonly(this, event, 'cents')"> <B>.</B> <INPUT NAME="cents" SIZE=2 MAXLENGTH=2 onKeyPress="return numbersonly(this, event)"> </FORM> This gives us this form: |