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

How to set a value from opener window

Status
Not open for further replies.

gorgered

Programmer
Dec 13, 2005
24
0
0
US
Hi,

I have to set the value of a textbox in a parent window from child window. The problem I am having is that the text field names in the parent window are numaric and when I am trying to set the value its not able to identify that html element.

Here is what I have, the openWindow will popup a window and popup window will set the value of param1 in the parent window and closes.

Parent window
Code:
<form name="form0">
 <input type="text" name="38" value="123"><img src="icon.find.gif" onClick="openWindow('findLocation.do?param1=38')" />
</form>

ChildWindow this is the script that puts the value for textfield 38. The param1 will have the inputField Name
Code:
 function setValues(param1, selectedValue){
 var parentForm = window.opener.document.forms(0);
 var parentField = eval("window.opener.document." + parentForm.name + "." + param1 );
 parentField.value = selectedValue;
 window.close();
 }

This code works when the text field name in the paramentForm is of type String.

Help is appriceated.

Thanks
Gorge
 
Would it bet much easier (and better practice) to make sure that the elements are not numerically named?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Hi,

The problem is that the form is generated dynamically from DB. I cannot change it now as a lot of other things are depedent on that. But I can pass a id for the text field as param. But the question is can I access that element with ID using window.opener

Thanks
Gorge
 
With such handicapped name attributes, the only practical and solid way is to do like this.
[tt]
function setValues(param1, selectedValue){
var parentForm = window.opener.document.forms[0];
for (var i=0; i<parentForm.length; i++) {
if (parentForm.elements.name==param1) {
parentForm.elements.value=selectedValue;
break;
}
}
window.close();
}
[/tt]
With w3c-compliant naming, your original function should be scripted simply like this.
[tt]
function setValues(param1, selectedValue){
var parentForm = window.opener.document.forms(0);
if (parentForm.elements[param1]) {
parentForm.elements[param1].value=selectedValue;
}
window.close();
}
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top