• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Using <SELECT> Controls

When the user makes a selection in a single-selection <SELECT> control (that is, a <SELECT> control that doesn’t include the MULTIPLE standalone HTML attribute), an onchange event occurs and you can use the selectedIndex property to get the current selection. Here’s an example that does exactly that:

(Listing 13-08.html on the web site)

<HTML> 
    <HEAD> 
        <TITLE> 
            Using Select Controls 
        </TITLE> 
        <SCRIPT LANGUAGE = JavaScript> 
            <!--
            function reportSelection()
					{
					document.form1.text1.value = “You chose item” +
					(document.form1.select1.selectedIndex + 1)
					} 
            //--> 
        </SCRIPT> 
    </HEAD> 

    <BODY> 
        <FORM NAME="form1"> 
            <H1>Using Select Controls</H1> 
            <INPUT NAME="text1" TYPE="TEXT" SIZE = "20"> 
            <BR> 
            <SELECT NAME="select1" ONCHANGE="reportSelection()">
					<OPTION>Option 1
					<OPTION>Option 2
					<OPTION>Option 3
					<OPTION>Option 4
					<OPTION>Option 5
					</SELECT> 
        </FORM> 
    </BODY> 
</HTML> 

					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint