Results 1 to 4 of 4

Thread: Set focus on Dropdown list?

  1. #1
    Join Date
    Aug 2003

    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")

    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 01:33 PM.

  2. #2
    Join Date
    Aug 2003

    test reply

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

  3. #3
    Join Date
    Aug 2003
    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:

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

  4. #4
    Join Date
    Dec 2002
    Manchester, UK
    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 2 users browsing this thread. (0 members and 2 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