this question has answer here:
- how prevent buttons submitting forms 13 answers
i have form on website , validating using js. issue have is, after form has failed validation, browser clears data has been inputted user.
i have tried stripping "submit" type value button , submitting form using js. code checks each field individually, keeping count of issues, , should submit if count > 0.
function validateform() { var errors = 0; // if test fails errors++ if(errors > 0) { alert("please correct following " + errors + " error(s):\n" + errorlist); return false; // assumed prevent form submitting } else { document.forms[0].submit(); } }
the code button is
html <button tabindex = "18" id = "submitform" onclick = "validateform();">submit</button>
this not restricted ie, occurs on firefox. form being submitted long fields complete regardless of errors.
for <button>
, default type submit
, set type button
if don't want submit.
Comments
Post a Comment