Yes, I know there are many questions on Stacked involving form validation but while some have been very close to what I'm trying to accomplish, I think this is unique.
I have this JS fiddle with this script that I want to use that will return all the fields by name that have not been filled out. I feel this is a much better approach as I was doing this below code to try to accomplish the same result with multiple field validation:
function validate ( )
{
valid = true;
if ( document.contactinfo.Name.value == "" )
{
alert ( "You need to fill the name field!" );
valid = false;
}
if ( document.contactinfo.email.value == "" )
{
alert ( "You need to fill in your email!" );
valid = false; //change variable valid to false
}
return valid;
}
While the above works and puts out multiple alert boxes, I manually have to alert them several times on what fields need to be filled out. I'd much rather send out an alert that tells them what fields they are missing in one fell swoop and return the focus to those fields. The JS fiddle script does that, however, I keep getting the error that: ValidateRequiredFields is not defined
and I don't see where the issue lies. I've named everything correctly and the form data should be getting passed up.
Any thoughts? As always, ask for clarification if needed. Thanks!
Note: I would not like to use JQuery as I know they have very easy plugins that allow you to set required classes!