http://www.pratee.com/reg Now I am checking for incorrect values, such as space in name or incorrect email ID using PHP. I have seen many people do it with Javascript. I did try making one and I got it right, but the validation onsubmit is not working, so I removed it. Can someone suggest a script for validation on submit?
You can also do it on the fly, not only at the point where the user submits the form. You need to have a Java Function that makes all the checks on the form, and then call it from the form. For checkbox and radio, use onClick. For text field and textarea use onkeyUp foe select drop-downs use onChange and call this function whenever the user changes something. A small example would be: <script type="text/javascript"> function SubButIf() { x1 = document.getElementById("xuser"); x2 = document.getElementById("xpassword"); if (x1.value.length >= 1 && x2.value.length >= 1) { ***do something, e.g. submit form*** } else { *** since either username or password is empty do not submit but display an alert or something **** } } </script> and then the form: <form method="POST" action="formsubmit.php"> <input type="text" name="xuser" id="xuser" size="20" onkeyUp="SubButIf()"> <input type="password" name="xpassword" id="xpassword" size="20" onkeyUp="SubButIf()"> <input type="submit" value="submit form"> </form> You can extend this to any point you'd like, or add any plus checks.