dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: Set focus on Dropdown list?

  1. #1
    Join Date
    Aug 2003
    Posts
    2

    Unhappy Set focus on Dropdown list?

    Hi all. This is my first time in here! I have a question. When a page loads up I want the focus to initially be set on a dropdown list. Right now it is set on a text box. Here is what the (javascript/html) code looks like:
    function SetFocus()
    {for (i=0; i<NumElements; i++)
    if (document.LANSA.elements[i].type == "textarea" ||
    document.LANSA.elements[i].type == "text" ||
    document.LANSA.elements[i].type == "checkbox" ||
    document.LANSA.elements[i].type == "radio")
    {document.LANSA.elements[i].focus();
    break;}
    }

    So how would I have a dropdown list (selection list) be part of those options, (since selection lists do not have a "type" property). Clear as mud? Thanks in advance!
    Last edited by fatglasses; 08-13-2003 at 02:33 PM.

  2. #2
    Join Date
    Aug 2003
    Posts
    2

    test reply

    This is just a test reply to myself, to make sure I did this right!

  3. #3
    Join Date
    Aug 2003
    Posts
    11
    I'm assuming that you know when the page loads which select box you want to focus on? If so, then you can set the focus as follows:

    <html>
    <head>
    <script language = "JavaScript">
    function setFocus(){
    document.form1.select1.focus();
    }
    </script>
    </head>
    <body onFocus = setFocus();>
    <form name = "form1">
    Text Box
    <input type = "text" name = "text1">
    <br>
    Select Box
    <select name = "select1">
    <option value = "1">Value 1</option>
    <option value = "2">Value 2</option>
    <option value = "3">Value 3</option>
    </select>
    </body>
    </form>
    </html>

  4. #4
    Join Date
    Dec 2002
    Location
    Manchester, UK
    Posts
    6,276
    It may be better to change this line:

    <body onFocus = setFocus();>

    to this:

    <body onload="setFocus();">

    because otherwise every time they switch to a differend window and come back to yours again it will set the focus back to the dropdown menu. That's fine if that's the effect your looking for but you did say:
    When a page loads up I want the focus to initially be set...
    so I thought I'd just mention it.
    Every fight is a food fight when you’re a cannibal.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles