The Select list is one of the most useful controls provided by HTML. This article demonstrates the incredible flexibility of the Select list and provides you with example code to do almost you could want with a Select list.
Welcome to Bucaro TecHelp!

Welcome to Bucaro TecHelp!
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact Advertise on Bucaro TecHelp Advertise Here RSS News Feeds News Feeds

HTML5 Solutions: Essential Techniques for HTML5 Developers

Essential Techniques for HTML5 Developers

HTML5 brings the biggest changes to HTML in years. Web designers now have new techniques, from displaying video and audio natively in HTML, to creating realtime graphics on a web page without a plugin.

This book provides a collection of solutions to all of the most common HTML5 problems. Every solution contains sample code that is production-ready and can be applied to any project.

Click Here

HTML Select List Basics

The Select list is one of the most useful controls provided by HTML. An HTML Select list is used to create a drop-down list of items from which the user can select. Each item in a select list is defined by an option element. The most basic code for a select list is shown below.

<select>
<option>Item 1</option>
<option>Item 2</option>
<option>Item 3</option>
</select>

We can access the select list with simple Java Script code, allowing us to control the appearance of the list, get the selected item or items, add items, remove items, or replace items in the select list. In this article, I'll provide easy Java Script code to do all that and more.

Using a Select List

When the user selects one of the items in a select list, an onchange event is triggered. The selectedIndex property will then contain the index of the item that the user selected. Select list option indexes start with 0 for the first item. The code below shows one way to access the index of the item that the user selected.

<script language="JavaScript">

function getSelection()
{
  alert(document.myForm.mySelect.selectedIndex);
}

</script>

<form name="myForm">
<select name="mySelect" onchange="getSelection()">
<option>Item 1</option>
<option>Item 2</option>
<option>Item 3</option>
</select>
</form>

Sometimes you'll want to work with the value of a list item rather than its index. In that case you can assign a value to the value attribute of each option element. In the code shown below we pass the list object to a function which displays the value of the selected option.

<script language="JavaScript">

function getSelection(list)
{
  alert(list.options[list.selectedIndex].value);
}

</script>

<form name="myForm">
<select name="mySelect" onchange="getSelection(this)">
<option value="Item 1">Item 1</option>
<option value="Item 2">Item 2</option>
<option value="Item 3">Item 3</option>
</select>
</form>

RSS Feed RSS Feed



Web Design Sections

HTML5 for Masterminds

HTML5 for Masterminds

How to take advantage of HTML5 to create amazing websites and revolutionary applications

This book is not an introduction of HTML5 but instead a complete course that will teach you how to build compelling websites and amazing web applications from scratch. Every chapter explores basic concepts as well as complicated issues of HTML5, CSS3 and Javascript.

Concepts are supported by fully functional codes to guide beginners and experts through every single tag, style or function included in the specification.

Click here for more information.


[Site User Agreement] [Advertise on This site] [Search This Site] [Contact Form]
Copyright©2001-2011 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268