Bostonasian wrote:
I am trying to append options to dropdown in parent window from option
items in child window.
In parent window, I have following code:
<script language="javas cript">
function AddItem2DropDow n(item){
exists = false;
for(d=0;d<drpDw n.length;d++){
if(drpDwn.optio ns[d].value == item.value)
exists = true;
}
if(exists == false)
drpDwn.options[drpDwn.length] = item;
}
</script>
Then in child window, I have following code:
<script language="javas cript">
function AddItems(child) {
for(i=0;i<child .length;i++){
if(child.option s[i].selected == true)
window.opener.A ddItem2DropDown (child.options[i]);
}
}
</script>
It works in Firefox, but not in IE6. Has anyone got this working in
IE6?
Not criticising, but I'm impressed that this works in any browser.
You've succeeded in 'cutting' an Option object from one window's list
box and 'pasting' it into a list box in an entirely different window.
You don't tell us which error you get in IE (at best, I get "the server
threw an exception"), but in any case I'd recommend a different approach.
Firstly, in your parent window, if you make your 'add' function a method
of the window, its existence can be easily tested for. Then, have it
create a completely fresh Option object based upon the parameter(s)
passed to it:
window.add2Drop Down = function(str, val)
{
var selBox = document.forms[0].elements["drpDwn"];
var opt = new Option;
opt.text = str;
opt.value = val;
selBox.options[selBox.length] = opt;
}
(I haven't duplicated your 'test if already exists' code).
In your child window, test for the existence: first, of the parent
window and then of the 'add' function. If successful, pass it the value
(or values) that indicate the Option you want to create:
....
if(window.opene r && window.opener.a dd2DropDown)
{
window.opener.a dd2DropDown(chi ld.options[i].text, child.options[i].value);
// then remove the item from the child's list box:
child.options[i] = null;
}...