Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2004
    Posts
    391
    Thanks
    76
    Thanked 0 Times in 0 Posts

    focus on first element of table

    I would like to place focus on the first input element of my table. I won't know the name of the field because the form is generated dynamically so I would just like to place focus on the first input element. How can I do this?

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    967
    Thanks
    19
    Thanked 211 Times in 209 Posts
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title> focus </title>
    </head>
    <body><div>
    <table id='tbl'>
      <tr>
    <td><input></td>
      </tr>
    <tr>
    <td><input></td>
      </tr>
    <tr>
    <td><input></td>
      </tr>
    </table>
    <div>
    <script>
    document.getElementById("tbl").getElementsByTagName("INPUT")[0].focus();
    </script>
    </body><html>
    or maybe the table has no id ?
    document.getElementsByTagName("TABLE")[0].getElementsByTagName("INPUT")[0].focus();

  • Users who have thanked DaveyErwin for this post:

    nikko50 (06-21-2012)


  •  

    Posting Permissions

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