spacer
Yehuda Shiran December 3, 2000
Modifying Options on the Fly in IE
Tips: December 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management
In tip 001201, we showed how Netscape 6 uses the DOM to let you modify options of the SELECT element, on the fly. Internet Explorer (as well as Netscape 6) supports it in the un intuitive way of looping through the OPTION objects with the item() method. The following drop-down menu includes two entries, Al Gore and George W. Bush. Here is the HTML code for this menu:

<FORM NAME="election">
<SELECT NAME="presidents">
<OPTION NAME="leaving">Al Gore
<OPTION SELECTED>George W. Bush
</SELECT>   <INPUT TYPE="button" VALUE="Switch first option" onclick="document.election.presidents.item(0).text =
 'Bill Clinton'">
</FORM>

The button on the right hand side has the following event handler:

onclick="document.election.presidents.item(0).text = 'Bill Clinton'";

Examine carefully the two menu options: Al Gore and George W. Bush. Click the button. In both Netscape 6 and Internet Explorer, the first option will be changed to "Bill Clinton".

Read more about the DOM in Columns 40, The DOM, Part I: Analysis, through 47, A DOM-Based Snakes Game, Part II.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags