Hi.. guys
I’m trying to use JavaScript to validate my HTML for empty fields. My code is as below. The problem is that I can escape validation and submit empty fields.
Any clue?
I’m trying to use JavaScript to validate my HTML for empty fields. My code is as below. The problem is that I can escape validation and submit empty fields.
Any clue?
Code:
<html> <head> <script language="JavaScript"> function isEmpty(inputStr,fieldname){ if (inputStr==null || inputStr==""){ alert("please fill in the box") document.form1.fieldname.focus(); document.form1.fieldname.select(); return false; } else { return true; } } </script> </head> <body> <form name="form1" method="GET" action=”?????????”> <p> User ID: <input type="text" name="txt1" onBlur="isEmpty(txt1.value,txt1.name)"/> <br /> <p> User Name: <input type="text" name="txt2" onBlur="isEmpty(txt2.value,txt2.name)"/> <br /> <br /> <input type="submit" VALUE="SUBMIT" /> </form> </body> </html>
Comment