Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Editing a textarea in a child window

Status
Not open for further replies.

basil3legs

Programmer
Jun 13, 2002
157
GB
I have tried everything I can think of to put text in a textarea in a child window opened via javascript. I can't get it to work. However, someone else had a look at this and came up with (which does work):

Code:
javascript:  var a=window.open("webpage.php");  alert(a.top);  a.top.document.getElementById("message").value='123';  alert(a.top.document.getElementById("message").value);

This works with the alert but won't if the alert is removed (and we don't want it there!). The form on the page has no name and the textarea is called "message".

Any suggestions?
 
The Problem is without the alert, the script keeps running and tries to access the textarea before its been created in the new window.

It takes time to create the Window, and the textarea inside, and without the alert, you script attempts to access it before its there.

You can attempt to use a delay script such as this one:






----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Aha, now that makes sense. However, when I try using setTimeout it clears the parent window and puts a number between 1 and 4 on it. On clicking back on this page, it does the update. I now have:

Code:
javascript:
var a=window.open("webpage.php");
timeout = setTimeout("a.top.document.getElementById('message').value='123';",2000);

Thanks for the help so far.
 
OK, I have now resolved this.

Code:
javascript: var win2=window.open("webpage.php"); var x = setTimeout("win2.top.document.forms[0].getElementById('message').value='123';",1000);

Does indeed work fine.

Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top