最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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?

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?

Share Improve this question edited Oct 3, 2013 at 6:53 sashkello 17.9k25 gold badges83 silver badges112 bronze badges asked May 30, 2012 at 23:52 user1306955user1306955 311 silver badge5 bronze badges 1
  • 1 "'patient' is the form name" - I assume you mean "the form id", given that you're using getElementById()? Please show your html, and perhaps how you call the settarget() function. – nnnnnn Commented May 30, 2012 at 23:57
Add a ment  | 

1 Answer 1

Reset to default 7

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)

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论