|
Subject:
|
Updating SELECT options list from new window
|
|
Posted By:
|
VorlonKen
|
Post Date:
|
2/9/2004 12:42:55 PM
|
My project is actually ASP, but I've boiled down my problem to JavaScript only. In fact, the code runs perfectly in Netscape and Mozilla, but fails in IE 6.0.2.
I must update the options list of a SELECT object from a newly opened browser window (from the same site). The new window generates a dynamic list from which the old list must be updated.
A very succinct illustration can be seen at http://vvv.dph.state.ct.us/page1.htm
There you can see a test HTML/javascript page that will update the list from a second list on the same page, and also a link to update it from a new window. (click refresh after trying the first example.)
Is there a BUG in IE that's preventing me from updating from the new browser window? Or must I do some special coding to make it work in IE?
|
|
Reply By:
|
joefawcett
|
Reply Date:
|
2/9/2004 4:21:02 PM
|
You can't directly manipulate select elements from another window. Options can only be added from the same window. If you look in the archive for posts by myself there is a long example of how to do this.
--
Joe
|
|
Reply By:
|
VorlonKen
|
Reply Date:
|
2/9/2004 4:22:48 PM
|
The answer is, YES, there is a bug in IE . To update the SELECT list you have to write a javascript function in the calling page, and then invoke that function from the new page.
|
|
Reply By:
|
joefawcett
|
Reply Date:
|
2/10/2004 9:07:18 AM
|
Technically speaking it's not a bug, if you look at the specification it's correct, nodes between documents are not interchangeable. It's caused by the fact select boex are separate windows, another side effect is that they don't respond to z-index. As I pointed out create the new option within the window or use opener property is changing select from a child window:
var oOption = window.opener.document.createElement("option");
oOption.text = "New";
oOption.value = 1;
window.opener.document.getElementById("lstBox").appendChild(oOption); //assuming your list box has an id of 'lstBox'
--
Joe
|
|
Reply By:
|
VorlonKen
|
Reply Date:
|
2/10/2004 10:59:46 PM
|
Thanks, Joe. I'm not familiar with your javascript syntax, especially the appendChild() method [which isn't documented in my rather old reference], but I'm sure you method will work as well as the one I devised from advice on another board.
However, I can't actually just append only new options to the list, I need to refresh the entire list. But you had no idea that was a requirement since I didn't get unnecessarily specific about my application.
It's interesting that you say that it's not allowed for one browser window to update the SELECT options in another window - since the browsers based on Mozilla support it just fine.
But that's OK, since the multiple work-arounds are supported by both browsers so it's better to use one of those.
|