select tag (XHTML 1.0)

option selector

The select element allows the user to select between a pre-defined range of elements. It comes in two different forms: A dropdown list or a listbox. This behavior is controlled by the multiple attribute, as described below. Here's an example of the select element, rendered as a dropdown list:




Each element in the select box is generated by using an option tag, like this:

<select name="Persons"> 
     <option>Select person...</option> 
     <option>Sajith Dilhan</option> 
     <option>Sajith Dilhan</option> </select>

The multiple attribute

A standard select list only allows the selection of one option, but what if we wanted our user to be able to select more than one? That's exactly what the boolean multiple attribute is for. Here's an example:

<select name="Persons" multiple="multiple"> 
     <option>Anyone</option> 
     <option>Sajith Dilhan</option> 
     <option>Siripala</option> </select>
The result will look like this:



Select one item by clicking it, and more items by holding down the or key on your keyboard while clicking.

Attributes

AttributeDeprecatedRequiredDescription
classspace-separated list of classes 
dirdirection for weak/neutral text 
disabledunavailable in this context 
iddocument-wide unique id 
langlanguage code 
multipledefault is single selection 
namefield name 
sizerows visible 
styleassociated style info 
tabindexposition in tabbing order 
titleadvisory title 

Events

EventDescription
onblurthe element lost the focus 
onchangethe element value was changed 
onclicka pointer button was clicked 
ondblclicka pointer button was double clicked 
onfocusthe element got the focus 
onkeydowna key was pressed down 
onkeypressa key was pressed and released 
onkeyupa key was released 
onmousedowna pointer button was pressed down 
onmousemovea pointer was moved within 
onmouseouta pointer was moved away 
onmouseovera pointer was moved onto 
onmouseupa pointer button was released 

Learn ASP.NET with C#(C-Sharp) in sinhala by Sajith Dilhan