Select.focus() : Select : Form JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Form » Select »

 

Select.focus()







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>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Form
» Select