programming.nbk: Home | Index | Next Page: HTML: Forms: text | Previous Page: HTML: Forms: radio button


 HTML: Forms: selection list

List boxes let you pick the item you want out of a multiple-choice box. The listbox itself is created with the tag.

The list can appear with many items showing at once, or it can appear in a drop-down box -- normally you see one item at a time, but click to see more. The markup for the two styles is identical, except for the optional SIZE attribute. Leave off SIZE to make a drop-down box; use SIZE to make a list box of the size you wish.

<SELECT NAME="list" SIZE="3">
<OPTION>This is item 1
<OPTION>This is item 2
<OPTION>This is item 3
</SELECT>

Use the selectedIndex property to test which option item is selected in the list:

function test_selection(form) {
    alert (form.list.selectedIndex);
}

If you want the text of the selected list item instead of the index, use this:

function testSelect (form) {
    Item = form.list.selectedIndex;
    Result = form.list.options[Item].text;
    alert (Result);
}

programming.nbk: Home | Index | Next Page: HTML: Forms: text | Previous Page: HTML: Forms: radio button


Notebook exported on Monday, 7 July 2008, 18:56:06 PM Eastern Daylight Time