Web Analytics Made Easy -
StatCounter Setting Focus Automatically on Form Fields - CodingForum

Announcement

Collapse
No announcement yet.

Setting Focus Automatically on Form Fields

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setting Focus Automatically on Form Fields

    There are many ways for setting focus on form fields. I'm actually looking for some code that automatically detects if there is any form on the page & then automatically sets the focus to the first field of the form.
    No need of putting Form Name & Field Name in Javascript.
    Is there any way to do this ???
    Please Help!!!

  • #2
    All you need is this piece of code:

    PHP Code:
    <script language="JavaScript">
    <!--
    objs document.getElementsByTagName('input');
    for(
    i=0i<objs.lengthi++) {
       if (
    objs[i].type == 'text') {
          
    objs[i].focus();
          break;
       }
    }
    //-->
    </script
    It will focus the first textbox in the page. Modify it a bit to get the first Combo, textarea, so on...
    so happy, so cool

    http://coolersport.info

    Comment


    • #3
      u mentioned PHP CODE. wot does this mean ? Can I only use this code in PHP pages or HTML too ???

      Comment


      • #4
        OMG, you didn't mention you were a newbie, j/k

        Putting thing in PHP tag make it colourful and readable. Please notice that they are in <script> tag.

        Cheers mate,
        so happy, so cool

        http://coolersport.info

        Comment

        Working...
        X