jquery - .Submit() not working -


i have skeleton below

@using (html.beginform("preapprove", "preapproval", formmethod.post, new { name = "form1", id = "form1", enctype = "multipart/form-data", @class = "form-horizontal" })) {   ...... <input name="submit" type="button" value="submit" id="sub" class="btn btn-success" style="margin-left:950px" />                         } 

and in jquery im submitting form on click of button id sub

$(document).ready(function () {             $('#sub').click(function (e) {               var error_flag = 0;                  if (d_row_count == 1) {                     error_flag = 1;                 }                 else if (d_row_count > 1) {                     if (code == null || code.trim() == '') {                         error_flag = 1;                      }                     else if (s_row_count == 1) {                         error_flag = 1;                     }                 }                 if (error_flag != 1) {                     alert("submitting");                     $("#form1").submit();                  }             }); 

when validation passed error_flag 0 , getting inside if condition , giving me alert "submitting" form not getting submitted.

anything im missing on code?

you need change name of input button "submit" else. having element named "submit" causes form's submit method no longer work, means form cannot submitted via javascript (at least, not easily).

the reason because input element named "submit" can referenced name this: form1.submit. is, input element added property of form object, property name being name of input element. hides submit function on form's prototype.


i "not easily" above, because following still works (at least in firefox):

htmlformelement.prototype.submit.call($("#form1")[0]); 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -