Check if text field input is a number : TextField « Form Control « JavaScript DHTML






Check if text field input is a number

   


<HTML>
<HEAD>
<SCRIPT LANGUAGE=JavaScript>
function butCheckForm_onclick()
{
   var myForm = document.form1;
   myForm.txtAge.blur();
   
   if (myForm.txtAge.value == "" || myForm.txtName.value == "")
   {
      document.write("missing value!");
      if (myForm.txtName.value == "")
      {
         myForm.txtName.focus();
      }
      else
      {
         myForm.txtAge.focus();
      }
   }
   else
   {
      document.write(myForm.txtName.value);
   }
}
function txtAge_onblur()
{
   var txtAge = document.form1.txtAge;
   if (isNaN(txtAge.value) == true)
   {
      alert("Age must be a number.");
      txtAge.focus();
      txtAge.select();
   }
}
function txtName_onchange() 
{
   window.status = "Hi " + document.form1.txtName.value;
   document.write(document.form1.txtName.value);
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME=form1>    Please enter the following details:
   Name:<INPUT TYPE="text" NAME=txtName onchange="txtName_onchange()">
   Age: <INPUT TYPE="text" NAME=txtAge onblur="txtAge_onblur()">
        <INPUT TYPE="button" VALUE="Check Details" NAME=butCheckForm onclick="butCheckForm_onclick()">
</FORM>
</BODY>
</HTML>

   
    
    
  








Related examples in the same category

1.Text field tab Index
2.Is Text Editable
3.Get vcard name
4.Text Field autocomplete Example
5.TextField focus and select all
6.Show TextField value in Dialog
7.TextField focus, blur, and click action
8.Display textfield value in new page
9.JavaScript Loan Calculator
10.Another TextField jump
11.TextField get Focus and clear content
12.Validate an input field with minimum and maximum values
13.Validate an field with a maximum number of characters
14.Select the textfield and focus
15.Focus an input field
16.Jump to the next field
17.Get textfield value
18. Methods and Properties of the Text Object
19.Selecting Text Upon Focus
20.Assign a default value to a Text object
21.Compound Interest Calculator
22.Resetting a Text Object to Default Value
23.Getting and Setting a Text Object's Value
24.Passing a Text Object (as this) to the Function
25.Text Object Select and Focus
26.Data Validation via an onChange event Handler
27.Add textfield dynamically into HTML
28. Firing the onSame Event (FireFox)
29.Numerals Only
30.Letter only, yes no only textfield
31.Auto focus textfield
32.Block enter textfield
33.If the textfield has been changed
34.Call select method to highlight the text field
35.Check if a text field is empty
36.Change the text value in text box into upper case
37.Getting and Setting a Text Object's value Property
38.Feed value from array to text box