Microsoft HomeproductssearchsupportshopWrite Us   Microsoft Home
Magazine
 |  Community
 |  Workshop
 |  Tools & Samples
 |  Training
 |  Site Info

Workshop  |  DHTML, HTML & CSS

selectedIndex Property


Sets or retrieves an integer specifying the index of the selected option in a SELECT object.

Syntax

HTMLN/A
Scriptingselect.selectedIndex [ = iIndex ]

Possible Values

iIndexInteger specifying the index.

The property is read/write with no default value.

Remarks

Options in a SELECT object are indexed in the order in which they are defined, starting with an index of zero. You can set the selectedIndex property at any time. The display of the SELECT object updates immediately when you set the selectedIndex property. Both forms of the syntax specify the same value.

In general, this property is more useful for SELECT objects that are created without the multiple attribute. If you evaluate selectedIndex when multiple options are selected, the selectedIndex property specifies the index of the first option only. Setting selectedIndex clears any other options that are selected in the SELECT object.

The selected property of the select object's options array is more useful for SELECT objects that are created with the MULTIPLE attribute. With the selected property, you can evaluate every option in the options array to determine multiple selections, and you can select individual options without clearing the selection of other options.

Example

In the following example, the user will be taken to the URL selected from the options as long as it is a change from the default value showing in the select list.

Sample Code

<SELECT onchange="window.location.href=this.options[this.selectedIndex].value">
<OPTION VALUE="http://www.microsoft.com/ie">Internet Explorer</OPTION>
<OPTION VALUE="http://www.microsoft.com">Microsoft Home</OPTION>
<OPTION VALUE="http://www.microsoft.com/msdn">Developer Network</OPTION>
</SELECT>

Applies To

HTML N/A
Scripting SELECT

Does this content meet your programming needs? Write us!

Back to topBack to top

© 1998 Microsoft Corporation. All rights reserved. Terms of use.

 

Magazine Home
Ask Jane
DHTML Dude
Extreme XML
For Starters
More or Hess
Servin' It Up
Site Lights
Web Men Talking
Member Community Home
Benefits: Freebies & Discounts
Benefits: Promote Your Site
Benefits: Connect with Your Peers
Benefits at a Glance
Online Special-Interest Groups
Your Membership
SBN Stores
Join Now
Workshop Home
Essentials
Content & Component Delivery
Component Development
Data Access & Databases
Design
DHTML, HTML & CSS
Extensible Markup Language (XML)
Languages & Development Tools
Messaging & Collaboration
Networking, Protocols & Data Formats
Reusing Browser Technology
Security & Cryptography
Server Technologies
Streaming & Interactive Media
Web Content Management
Workshop Index
Tools & Samples Home
Tools
Samples, Headers, Libs
Images
Sounds
Style Sheets
Web Fonts
Training Home
SBN Live Seminars
SBN Live Chats
Courses
Peer Support
CD-ROM Training
Books & Training Kits
Certification
SBN Home
New to SBN?
What's New on SBN
Site Map
Site Search
Glossary
Write Us
About This Site