Unable to set form action via javascript (error:object doesn't support this property or method)

隐身守侯 提交于 2020-01-15 03:08:25

问题


Here is the code. patient is the form name.

function settarget(page) {
    document.getElementById('patient').action = page;
}

The exact error message from IE is:

SCRIPT438: Object doesn't support this property or method 

I have also tried it referencing document.forms[0].action - same error.

There is no duplication of the name patient for any other tag.

This works with Chrome and Firefox, but not IE8 on XP or IE9 on Win7. Is there a security setting in IE that is blocking this action?


回答1:


DOM elements (returned by getElementById) do not have a property action. You need to set an attribute on the element.

document.getElementById('patient').setAttribute('action',page)


来源:https://stackoverflow.com/questions/10825806/unable-to-set-form-action-via-javascript-errorobject-doesnt-support-this-prop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!