开发者

HTML form submission using wrong field names when invoked from onChange handler

In my jQuery-validation "submitHandler", I'm renaming some fields so that they have the same name (this is required by the server which is handling the form) before invoking form.submit().

This works find when I click on the submit button - I see the correct parameter names being sent to the server (using wireshark).

If however the form is submitted as a result of a change handler then the fields appear to be renamed when I'm stepping through the code in the debugger - but the parameters that get sent to the server shows the original field names instead of the ren开发者_C百科amed values.

There's nothing special about my change handler ...

$(document).ready(function() {
  $('.autoSubmitField').bind('change', function() {
      $(this).closest("form").submit();
  });
});

Any idea what I'm doing wrong? Why does a regular form submission (via the submit button) honour the name change .. but a form submission via my onChange handler does not?

Cheers!


It appears that the jQuery plugin does not use onsubmit handler, but adds onclick to the submit button. Pretty crappy design if that is the case. Instead of calling submit, call click on your submit button.

$("#submitButtonId").click();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜