Debugging Form Validation in Javascript
Prerequisites
Accompanies form validation assignment in COP4813
Summary
Topics covered:
Simplifying form validation
Video
Reference Materials
http://jsfiddle.net/reaglin/wZxTQ/ – Code for program
<!DOCTYPE html> <html> <head> <title>Form Example</title> <script type="text/javascript"> function ValidateForm() { alert("Now Validating Form"); if (!ValidateNotBlank(document.forms["inputForm"]["fname"].value, "First Name" )) return false; if (!ValidateNotBlank(document.forms["inputForm"]["lname"].value, "Last Name" )) return false; return true; } function ValidateNotBlank(val, message) { alert("Now validating Not blank"); if (val == null || val == "") { alert("Must enter a value for " + message); return false; } return true; } </script> </head> <body> <form name="inputForm" onsubmit="return ValidateForm();" method="post" action="mailto:eaglinr@daytonastate.edu" > Input First Name: <input type="text" name="fname" /><br/> Input Last Name: <input type="text" name="lname" /><br/> <input type="submit" value="submit" /> </form> </body> </html> |