|
|
|
<head>
<script language="javascript">
function checkNumber (){
/*
Declare the local variables
*/
var value
var message
/*
Make value the same value of the text field by accessing the document
object and then by getting that to reference "myForm" object and finally
accessing myTextField's value in the form.
*/
value = document.myForm.textField.value
/*
Check if the value is Not a number or if it is a empty string
*/
if(isNaN(value) || value == "" ){
/*
Set the message variable
*/
message = "The value[" + value + "] is NOT a number"
}else{ //It's a number
message = "The value [" + value + "] is a number"//Set the message variable
}
alert(message)//Show a model dialog with the message
}
</script>
</head>
<!--
<body><!-- Open the body tag -->
<form name="myForm"><!-- Open the form element and give myForm as it's name -->
<!-- Define the text field and give it the name myTextField-->
<input type="text" name=" myTextField ">
<!-- Define the button and make it's onClick event call checkNumber -->
<input type="button" value="Check number" onclick="checkNumber()">
</form><!-- Close the form -->
</body><!-- Close the body element -->