Submit button clicked via javascript doesn't "submit" in IE6
For reasons I won't go into we need to click a submit button (as opposed to a plain button) via Javascript.开发者_开发知识库
We do this by getting a handle to the submit button, then executing the .click() method on this button. This works perfectly in FireFox, but in IE6 it only works partially.
The button receives the click, and code associated with the buttons "onClick" event fires (we can observe this by watching the server-side code in the debugger) however, the page never "refreshes" the way it should when clicking a "submit" button.
Since this works in FireFox, we assume it is yet another IE6 bug, but I'm not having any luck finding a work-around. We can't simply refresh the page directly because we need it drawn as though it were drawn from the submit button POST request.
Wouldn't it be easier to get a reference to the form element and fire the submit
event?
var form = document.forms[0];
form.submit();
I have the same issue in ASP.net. We must "click" the button because there is more that happens in ASP.net with a form than just the normal .submit() on the form. It has to know which button you clicked so it can match it up to the Click event on the server-side for that button.
Try using setTimeout to delay the click by 1 millisecond.
精彩评论