javascript - Wait for the return of the loop on form submit -
I have the following code, it is necessary to validate the form before submitting it to the form but the problem is that, Submitting the form continues without submitting.
& lt; Form action = '#' method = 'post' onsubmit = 'return validate ();' & Gt; Validate the function () {$ ('form'). (': Input: No (submit, hidden), select, Textera'). Each (function (e) {$ (this) .removeClass ('redbox'); var rq = $ (this) .attr ('requiredz'); if (rq! = Undefined) {if ($ (this) .val (). Trim () == '') {$ (this) AddClass ('redbox'); $ ("# errorMsg") .HTML ('The red box can not be left empty!'); Return back; }}}); });
How to handle the return of a loop? Do not submit the form after facing the lie to return to the loop.
Try this:
function () {var passes = True; $ ('Form'). (': Input: No (submit, hidden), select, Textera'). Each (function (e) {$ (this) .removeClass ('redbox'); var rq = $ (this) .attr ('requiredz'); if (rq! = Undefined) {if ($ (this) .val ('' Red boxes can not be left! ''); Pass = False;}}}); Return pass; });
Comments
Post a Comment