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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    How to define the focus on page load?

    Hi, I'm using ColdFusion to handle the login function for users (see login_form.cfm below). Have to click in the username box to be able to start typing. What's the best way to define the focus to be on the username when the page initially loads?

    Thanks

    <form method="post">
    Username: <input type="Text" name="username"><br>
    Password: <input type="Password" name="password"><br>
    <input type="Submit" value="Login" name="login">
    </form>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,144
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    Code:
    <body onload="document.formname.elementname.focus()">

    Quizmaster: A peak in the Andes was confirmed by an expedition in 2000 to be the source of which river?
    Contestant: The Nile.

  • Users who have thanked Philip M for this post:

    turbo79 (06-22-2010)

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    What's the best way to define the focus to be on the username when the page initially loads?
    Code:
    <script type="text/javascript">
    window.onload=function(){
    var elm=document.getElementById('username');
    elm.focus();
    }
    </script>
    Code:
    <input type="Text" name="username" id="username">
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    turbo79 (06-22-2010)

  • #4
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks Guys. Your tips and this page:
    http://www.htmlcodetutorial.com/form...amsupp_97.html

    did the trick. Here's the working code in case anyone else is interested.

    <body onload="document.forms.login.username.focus()">

    <form name="login" method="post">
    Username: <input type="Text" name="username"><br>
    Password: <input type="Password" name="password"><br>
    <input type="Submit" value="Login" name="login">
    </form>
    Last edited by turbo79; 06-22-2010 at 06:29 PM.


  •  

    Posting Permissions

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