Select.focus() : Select « Form « JavaScript Tutorial






The focus() method gives the focus to the select box.

<html>
    <head>
    <script language="JavaScript">
    <!--
    function setFocus(num){
      if(num == 1){
        document.myForm.mySelect1.focus();
      }else if(num == 2){
        document.myForm.mySelect2.focus();
      }
    }
    -->
    </script>
    </head>
    <body>
    <P>
    <form name="myForm">
      <select name="mySelect1" multiple>
        <option value=A>AA</option>
        <option value=B>BB</option>
        <option value=C>CC</option>
        <option value=D>DD</option>
      </select>
      <input type=BUTTON value="Click to Set Cursor" name="myButton1"
             onClick="setFocus(1)">
      <br>
      <select name="mySelect2" multiple>
        <option value=E>EE</option>
        <option value=F>FF</option>
        <option value=G>GG</option>
        <option value=H>HH</option>
      </select>
      <input type=BUTTON value="Click to Set Cursor" name="myButton2"
             onClick="setFocus(2)">
    </form>
    </body>
    </html>








10.12.Select
10.12.1.Select
10.12.2.Select.blur()
10.12.3.Select.focus()
10.12.4.Select.form
10.12.5.Select.handleEvent()
10.12.6.Select.length
10.12.7.Select.name
10.12.8.Select.onBlur
10.12.9.Select.onChange
10.12.10.Select.onFocus
10.12.11.Select.options
10.12.12.Select.options.length
10.12.13.Select.options.selectedIndex
10.12.14.Select.options.value
10.12.15.Select.selectedIndex
10.12.16.Select.type
10.12.17.Triggering a Value Change from a Pop-Up Menu
10.12.18.Grouped selection control on change event