PDA

View Full Version : returning value to <select> box in IE..


nkrgupta
12-07-2005, 11:29 AM
Hi,
I have a select box which has a "Create category" option. When this option is selected, a popup appears where the user can enter a name and a category by that name is created on clicking the submit button. what i want though is that the newly created category name be sent back as an additional <option> to the parent select box (in the previous page), apart from all the server side operations, which are running smoothly now. I got this following piece of code which is doing exactly what i require, but only in FireFox. I want it to work in IE as well, but the select box is not being populated...
Any clues....?

This is the JS function within the <body> tag of the popup --

<script language="JavaScript">
function add(option,oSelect)
{
var n = document.createElement('option');
n.innerHTML = option;
n.setAttribute('value',option);
oSelect.appendChild(n);
}
add('$name',window.opener.document.forms[0].elements['cat_sel']);
</script>

The whole thing is a CGI affair.. In the above code, $name is the name of the category which i'm getting from my cgi and 'cat_sel' is the name of the <select> box in the parent page.

Thanks
Naveen

Kor
12-07-2005, 12:05 PM
new created elements must belong to their windows.
Try this:

<script type="text/javascript">
function add(option,oName)
{
var oSelect = window.opener.document.forms[0].elements[oName];
var n = window.opener.document.createElement('option');//must belog to its page
n.appendChild(window.opener.document.createTextNode(option));
n.setAttribute('value',option);
oSelect.appendChild(n);
}
add('$name','cat_sel');
</script>

Use type instead of deprecated language script attribute.

nkrgupta
12-07-2005, 12:37 PM
Thanks kor... Though i did it in some other way, i'll try out your script..