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 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

本文标签: javascriptUncaught TypeError Cannot set property 39value39 of undefined in Google ChromeStack Overflow