admin管理员组文章数量:1410730
In my page A, there is a textarea defined like this:
<textarea readonly wrap="Physical" cols="50" rows="2" name="Attr">
The page A opens page B in a popup (by window.open('PageB')
).
In the page B, the button "Save" executes this line of code:
window.parent.opener.document.all.Attr.value='Value 1, Value 2,';
This one causes an error in Google Chrome (error: "Uncaught TypeError: Cannot set property 'value' of undefined") but works perfectly with Internet Explorer and Mozilla Firefox. I have read that document.all
is old and should be replaced by document.getElementById
which I did but with no success (error: "Uncaught TypeError: Cannot set property 'value' of null").
If I replace document.all
by document.forms[0]
, it works in all browsers including Google Chrome. But that doesn't seem to be a good solution as the page B could be called by other pages than Page A and that could have more than one form.
Could anyone tell me what I am doing wrong?
Thanks in advance!
Opec.
In my page A, there is a textarea defined like this:
<textarea readonly wrap="Physical" cols="50" rows="2" name="Attr">
The page A opens page B in a popup (by window.open('PageB')
).
In the page B, the button "Save" executes this line of code:
window.parent.opener.document.all.Attr.value='Value 1, Value 2,';
This one causes an error in Google Chrome (error: "Uncaught TypeError: Cannot set property 'value' of undefined") but works perfectly with Internet Explorer and Mozilla Firefox. I have read that document.all
is old and should be replaced by document.getElementById
which I did but with no success (error: "Uncaught TypeError: Cannot set property 'value' of null").
If I replace document.all
by document.forms[0]
, it works in all browsers including Google Chrome. But that doesn't seem to be a good solution as the page B could be called by other pages than Page A and that could have more than one form.
Could anyone tell me what I am doing wrong?
Thanks in advance!
Opec.
Share Improve this question asked Jan 13, 2014 at 15:08 OpecOpec 851 gold badge3 silver badges10 bronze badges1 Answer
Reset to default 1Why can't you just assign it an id an access it through that?
<textarea id="text" readonly wrap="Physical" cols="50" rows="2" name="Attr">
and in your javascript
document.getElementById("text").value="Value 1, value 2"
Here is a JSFiddle demonstrating it
版权声明:本文标题:javascript - Uncaught TypeError: Cannot set property 'value' of undefined in Google Chrome - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744895755a2631053.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论