Alert non number form input in JavaScript

Description

The following code shows how to alert non number form input.

Example


<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
function myErrorHandler(data){<!--from w  w w.  ja  v a2 s . co  m-->
try{
if(data == "string"){
throw "E0";
}else{
throw "E1";
}
}catch(e) {
if(e == "E0"){
return("Error (" + e + "): Entry must be numeric.");
}else{
return("Error (" + e + "): Entry must be numeric.");
}
}
}
function processData(form){
if(isNaN(parseInt(form.myText.value))){
alert(myErrorHandler("string"));
}else{
alert("You have correctly entered a number");
}
}
</script>
<form name="myForm">
Please enter a number:
<input type=TEXT size=10 value="" name="myText">
<input type=BUTTON value="Process" name="myButton" onClick='processData(this.form)'>
</form>
</body>
</html>

Click to view the demo

The code above generates the following result.

Alert non number form input in JavaScript
Home »
  Javascript Tutorial »
    Form »
      Text Input
Javascript Tutorial Text Input
Alert non number form input in JavaScript
Get the input value for input text in JavaS...
Get the value in TextArea in JavaScript
Pass form to a function and display its val...
Set value to input text form control in Jav...
Set value to input text in JavaScript