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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setTimout - other Window field value setting

Status
Not open for further replies.

Noonoo

Technical User
Jul 16, 2002
35
GB
Hi.

I've written a function which sets a variable (ParentWin) equal to the current window's opener. If an opener does'nt exist it opens a new window and sets the ParentWin as that. This gaurantees there's another open window that can referenced.

I've written a 2nd function, which takes two parameters and sets form field values in ParentWin equal to the parameters. This works too.

Both functions don't work together if ParentWin is'nt already open. I think the 2nd function needs calling within setTimeout() to allow the window to fully open first . Whenever I try this I get errors though.

In summary I want to 1) Set or open Parent Win 2)Update form fields values in Parent once or provided it's open.

Has anyone come up against a problem like this. If you've got working code I could borrow and adapt that would be ideal.

Here's the 2 functions:

var ParentWin
function setParentWin()
{if (ParentWin && !ParentWin.closed)
{//ParentWin is open - no action needed
}
else if (opener && !opener.closed)
{//Set ParentWin as the page that opened this window
ParentWin = opener;
}
else
{//Open a new Parent Window and call it ParentWin
ParentWin = window.open('TestParent.asp','Outputs','');
}}

function populateParent(projectID, projectTitle)
{
setParentWin();
ParentWin.focus();
ParentWin.OutputsForm.ProjectID.value = projectID;
ParentWin.OutputsForm.ProjectTitle.value = projectTitle;
}

Thanks for your time
 
I've not tested this, but try it anyway:

Code:
function populateParent(projectID, projectTitle) {
	setParentWin();
	setTimeout(actualPopulate(projectID, projectTitle), 1000);
}

function actualPopulate(projectID, projectTitle) {
	ParentWin.focus();
	ParentWin.OutputsForm.ProjectID.value = projectID;
	ParentWin.OutputsForm.ProjectTitle.value = projectTitle;
}

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top