Jump to content

How To Validate A Form


natasha23

Recommended Posts

i am trying to write a function to validate more than one mandatory field on my formthis is the code i have which validates i field within my form:function checkForm(){var q1= document.getElementsByName("enrolled")for(var i=0; i < q1.length; i++)if(q1.checked)return true;alert ("You must fill in all of the mandatory fields!")return false} else return true}although this function will not work when i want to add another field.is there a way to validate an entire form with mandatory fields using on function which is called by onsubmit???thanks in advance

Link to comment
Share on other sites

Yes, the reason this function only works for one is because it immediately returns true after it checks the one field. You would need to use a variable to keep track of whether or not the form is valid, and return that one variable at the end.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...