[Solved] how to show an alert box In javascript


If you want to check if the user has entered a number or not, you could use isNaN:

function foo() {
 var a = document.getElementById("inputField").value;
 if (isNaN(a)) 
 {
 alert("Must input numbers");
 }
 else
 {
 alert("its a number");
 }
}

where inputField is the ID of your input field. Of course you can use

 if (isNaN(a)) 
 {
 alert("Must input numbers");
 }
 else
 {
 alert("its a number");
 }

in any context, you don’t have to place it in an apart function like I did here.
JSFiddle: http://jsfiddle.net/m5cTr/1/

16

solved how to show an alert box In javascript