PDA

View Full Version : Update parent window with text from option in select tag


raven
02-07-2003, 11:37 AM
I am using the following function to update a parent window with a value selected in a child window:

function updatetext(SOURCE,TARGET)
{
opener.document.all[TARGET].innerHTML=document.all[SOURCE].value;
}

This is called using:

onChange="javascript:updatetext('txtTown','divTown');">

In this example txtTown is the form field name in the child window and divTown is the div name in the parent window.

This works fine for a text input field, but for a select field the parent window div is update with the value, which is numeric, and I want to pass the associated text. For example:

<select name="cboCountry">
<option value=1 id=England>England</option>

Using:

onChange="javascript:updatetext('cboCountry','divCountry');"

updates the parent window to the value 1.

How do I get this to update the parent to the text, in this case "England"?

requestcode
02-07-2003, 01:03 PM
Try changing this line:
opener.document.all[TARGET].innerHTML=document.all[SOURCE].value;

To this:
opener.document.all[TARGET].innerHTML=document.all[SOURCE].text;

You should also know that using document.all will limit the code to IE. This will not work in NS browsers.

raven
02-07-2003, 01:20 PM
Thanks.

I have tried this, but the parent window is updated with the value 'undefined', rather than the text from the option selected in the child window.

99.7% of my users are using IE, but I guess I'd better cater for the remaining few. What would I need to change to make this NS friendly?