javascript - Uncaught TypeError: Cannot set property 'value' of undefined in Google Chrome - Stack Overflow

In my page A, there is a textarea defined like this:<textarea readonly wrap="Physical" col

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 badges
Add a ment  | 

1 Answer 1

Reset to default 1

Why 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744895755a4599685.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信