SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Forms and cursors

    Hello!

    Is the following possible, if so how.

    Open up another Site of SitepointForums, click on new topic, a form shows up, what i want to know is, can i have the cursor placed immediately into the Topic field?

    As you can see, you will have to click manually into the Subject Field to be able and start writing, now this is not really annoying on a forum, but we are deploying something where one works lots of times with forms, and during testphase i found this to be extremely annoying after some time.

    So please if someone knows a solution for this, (i think it should be possible somehow), please let me know.

    Thanks a lot in advance!

    Best regards from Vienna,
    datune

  2. #2
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes it is possible with JavaScript:


    Code:
    <body onLoad="document.forms[0].elements[x].focus()">
    // where x is the xth element of the form 
    // or this should work as well:
    <body onLoad="document.forname.elementname.focus()">

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2002
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    focus

    i am sorry i don't have time to post the code but -- i used to use a javascript to set "focus" to a given form element. but on other sites - i just use my keys to tab down to the element i want.
    anyway - a quick search for "form focus" either here or out in the wild should help you find it quickly.

    good luck.

  4. #4
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot!
    Though i still have to find a way to prevent it from setting the focus on a radiobutton or a checkbox if that happens to be the first in a form.

    Is it possible in Javascript to do something like

    if the first element of the form is a radio or checkbox-> set focus on next element in form

    else set focus on the first element of the form.

    Is this somehow possible, if someone who knows Javascript would be willing to help out, that would be great, since i never digged deep if it comes to Javascript...

    Thanks!

  5. #5
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe this works. (could be problems if type is not all lowercase)

    Code:
    <script language="JavaScript">
    <!-- 
    function  doFocus() {
       var nexttype = document.forms[0].elements[0].type;
    
       if ((nexttype == "radio" || nexttype == "checkbox") && 1 < document.forms[0].length - 1)
            document.forms[0].elements[1].focus();
    
       else
          document.forms[0].elements[0].focus();
    }
    //-->
    </script>
    And then for the body element:

    Code:
    <body onLoad="doFocus()">
    //html
    </body>


Bookmarks

Posting Permissions

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