Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 9th, 2004, 01:42 PM
Authorized User
 
Join Date: Feb 2004
Location: , CT, USA.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Updating SELECT options list from new window

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?
 
Old February 9th, 2004, 05:21 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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
 
Old February 9th, 2004, 05:22 PM
Authorized User
 
Join Date: Feb 2004
Location: , CT, USA.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
Old February 10th, 2004, 10:07 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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:
Code:
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
 
Old February 10th, 2004, 11:59 PM
Authorized User
 
Join Date: Feb 2004
Location: , CT, USA.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
IE 7 form select options harpua HTML Code Clinic 0 May 9th, 2007 11:59 PM
adding options to a select element dymanicly StevesonD Javascript How-To 0 September 28th, 2006 09:53 AM
Drop Down options to select stream for Listener sam8599 Javascript 0 May 29th, 2006 12:18 PM
How do I restrict options with Select Case jdyates Classic ASP Basics 3 August 3rd, 2004 02:55 PM
Select Options ~ "multiple" attribute phungleon SQL Server 2000 2 July 21st, 2004 10:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.