I am writing a basic form validation script, basically as we go through the form each field is checked onblur like this
<p>
<label>Full Name *</label>
<input type=text id=fullName value= onblur=validate('FullName', 'fullName'); />
<span class=formHint id=hintFullName>Enter your full name</span>
<span id=errorFullName></span>
<span class=success id=successFullName><img src=images/tick.png /></span>
</p>
This all works fine calling the function validate which I made so that you could pass it the field name and it will just check if it has been entered etc. This is all fine. Below is the validate function.
function validate(field) {
// Get the value of the input field being submitted
value = document.getElementById(field).value;
// Set the error field tag in the html
errorField = 'error' + field;
// Set the success field
successField = 'success' + field;
if (value != '') {
document.getElementById(successField).style.display = 'block';
document.getElementById(errorField).style.display = 'none';
} else {
document.getElementById(successField).style.display = 'none';
document.getElementById(errorField).style.display = 'block';
}
}
Now my question is, after validating on the fly using the onblur what is the best way for me to proceed when submitting? Do I need to write another function to manually check all of the form fields or is there a better way.
I have been thinking about it for a while but I cant seem to think the best way to check once submitted.
Sorry if any of this doesn't make sense, been confusing myself for a few hours now.
Many thanks in advance.