spacer
Yehuda Shiran January 18, 2000
The Option Constructor
Tips: January 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

The Option object is contained by the Select object. The Select object may have many options. They are contained in its options[] array. Here is an example for a reference to an option:

document.forms[3].elements[2].options[5]

The option objects can be create dynamically at runtime, via the Option constructor. The syntax for creating an option is as follows:

var optionObj = new Option([optionText, optionValue, defaultSelected, selected]);

where:

  • optionText is a string representing the option's text property
  • optionValue is a string representing the option's value property
  • defaultSelected is a string representing the option's defaultSelected property
  • selected is a string representing the option's selected property

You can add an option to an existing select object in the following fashion:

selectman.options[index] = optionObj;

After you create an option and add it to a Select object, you must refresh the document. One way to refresh the document is by using the following JavaScript statement:

history.go(0)

You can also delete an option from a Select object, by assigning it a null value. The general syntax will then be:

selectName.options[index] = null;


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint