开发者

How to get Javascript to post a form?

I am using the f开发者_JAVA百科ollowing code: document.forms["form_name"].submit(); It doesn't seem to work. Is there another way to submit a form using Javascript?


Not really. It probably doesn't work because you have form element named "submit". Change its name and the code will work.

To confirm this is really the problem, some debug is required:

var sFormName = "form_name";
var oForm = document.forms[sFormName];
if (oForm) {
   if (oForm.elements["submit"]) {
      alert("form contains element named submit, can't use JS to submit it");
   }
}
else {
   alert("Form named " + sFormName + " does not exist");
}

Keep us updated. :)


If you're in Internet Explorer, there HAS to be a <input type='submit'> present in the form in order to work. May just be IE7, but we've run into that problem.

To hide the button just use style='display:none;'

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜