I have a form on a website and I am validating it using JS. The issue I have is, after the form has failed validation, the browser clears the data which has been inputted by the user.
I have tried stripping the "submit" type value from the button and submitting the form using JS. My code checks each field individually, keeping count of any issues, and should only submit if the count > 0.
function validateForm()
{
var errors = 0;
// if test fails errors++
if(errors > 0)
{
alert("Please correct the following " + errors + " error(s):\n" + errorList);
return false; // I assumed this would prevent the form submitting
}
else
{
document.forms[0].submit();
}
}
The code for my button is
HTML
<button tabindex = "18" id = "submitForm" onclick = "validateForm();">Submit</button>
This is not just restricted to IE, it also occurs on Firefox. It is like the form is being submitted as long as all fields are complete regardless of errors.