Data Validation via an onChange event Handler : TextField : Form Control JAVASCRIPT DHTML TUTORIALS


JAVASCRIPT DHTML TUTORIALS » Form Control » TextField »

 

Data Validation via an onChange event Handler



<HTML>
<HEAD>
<TITLE>Text Object Select/Focus</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function isNumber(inputStr) {
    for (var i = 0; i < inputStr.length; i++) {
        var oneChar = inputStr.substring(i, i + 1)
        if (oneChar < "0" || oneChar > "9") {
            alert("Please make sure entries are numbers only.")
            return false
        }
    }
    return true
}
function checkIt(form) {
    inputStr = form.numeric.value
    if (isNumber(inputStr)) {
        // statements if true
    else {
        form.numeric.focus()
        form.numeric.select()

}
}
</SCRIPT>
</HEAD>
<BODY onSubmit="checkIt(this); return false">
<FORM>
Enter any positive integer: <INPUT TYPE="text" NAME="numeric"
 onChange="checkIt(this.form)"><P>
</FORM>
</BODY>
</HTML>

           
       



-

Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

JAVASCRIPT DHTML TUTORIALS

 Navioo Form Control
» TextField