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!

post back data to parent window 1

Status
Not open for further replies.

nmath

Programmer
Dec 12, 2003
47
0
0
US
I have a pop up and would like to send the data back to window that created the pop up with out posting the page. To be more specific, I have a form, and would like to allow a user to select values out of a popup and those values selected will populate the form in the parent window. Any suggestions would be very much appreciated!!!
 
In the popup you would write:
Code:
var parentField=opener.document.parentFormName.parentFieldName;
var popupField=document.popupFormName.popupFieldName;
parentField.value=popupField.value;

If the popup field is a select box, then it would be like this:
Code:
var parentField=opener.document.parentFormName.parentFieldName;
var popupField=document.popupFormName.popupSelectName;
parentField.value=popupField[popupField.selectedIndex].value;



Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
Thank you so much!!! That worked really well.
 
OK, the above code worked wonderfully for input boxes on the parent window, however when I try to put options in a select box I get the follwing error "The server has thrown an exception" after which I get an IE error saying my browser is going to close. Obviously something is seriously wrong. Here is my code:
Code:
function fillin()
{

var selectedItem = document.Mainform.req.selectedIndex;

if (selectedItem == -1)
  alert("You have not selected a field!")
else{
var selectedText = document.Mainform.req.options[selectedItem].text;
var selectedValue = document.Mainform.req.options[selectedItem].value;
var i;
var isNew = true;

if (isNew) {
newoption = new Option(selectedText, selectedValue, false, false);
opener.document.Mainform.chosenreqs.options[0] = newoption;
}

}
window.close();

}

Thanks in advance!!!
 
Well, I think I figured it out!

Code:
function fillin()
{
var boxLength = opener.document.Mainform.chosenreqs.options.length++;
var selectedItem = document.Mainform.req.selectedIndex;

if (selectedItem == -1)
  alert("You have not selected a field!")
else{
var selectedText = document.Mainform.req.options[selectedItem].text;
var selectedValue = document.Mainform.req.options[selectedItem].value;
var i;
var isNew = true;

if (isNew) {
var length = 0;
opener.document.Mainform.chosenreqs.options[boxLength].text = selectedValue;
}

}
//window.close();

}
 
For security purposes, you may have to put the function that adds the option to the select list in a function in the parent window and then call the function from the popup using opener.functionName(arg1,arg2,etc)

To add the new option, try using the .add() method of the SELECT object as seen at
Set the text and value after the option has been added.

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top