Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Web
Expertise: Beginner
Feb 9, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Present Lists Using the SELECT Control

You can use the SELECT control to present a predefined list to the user. The SELECT control is useful for quickly selecting one or more items from a predefined or dynamically generated list from the database. You can implement the SELECT control in different ways, including a drop-down list, a list box, or a multi-select list box. These use a combination of SIZE and MULTIPLE attributes.

To populate the control, you use the OPTION object. To get hold of the selected value(s), you need the reference of the control and the selected option. To retrieve the selected value, you use the SelectedIndex property with the options collection to identify the particular item.

In order to retrieve the selected values from a multi-select list, you need to iterate through all the options. The selected property can be queried to determine if the option is selected. If so, you can use the current index of the iteration to acquire the text or value of the item.

When a multi-select list is submitted, the items are sent as a comma-delimited list. If a VALUE attribute is not provided as an option, the TEXT attribute is sent instead.

Drop-down list

SELECT ID="CityList">
<OPTION Value="1">Waltham
<OPTION Value="2">Lowell

List box

SELECT ID="CityList" SIZE="2">
<OPTION Value="1">Waltham
<OPTION Value="2">Lowell

Multi-select list box

<OPTION Value="1">Waltham
<OPTION Value="2">Lowell
<OPTION Value="2">Lexington
Deepak Pant
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date