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 3 of 3

Thread: onFocus

  1. #1
    New Coder
    Join Date
    Sep 2006
    Posts
    32
    Thanks
    5
    Thanked 0 Times in 0 Posts

    onFocus

    This is most likely a real easy questions to answer

    When this form loads, eI would like the cursor to be in the input box.

    Code:
    <form action=/prep/index.php?add=y method="post">
    <p>Church ID: 1<br>Survey 3 of 20</p>
    <p>Survey Identification Number: <input type="text" name="sid"></p>
    <input type="hidden" name="churchid" value="1">
    <input type="hidden" name="count" value="3">
    <input type="submit" name="do" value="Submit">
    </form>
    Thanks
    jlimited

  • #2
    Regular Coder BWiz's Avatar
    Join Date
    Mar 2006
    Location
    Sol System
    Posts
    471
    Thanks
    7
    Thanked 21 Times in 21 Posts
    JavaScript
    Code:
    <script type="text/javascript">
    <!--
    function focusField(f-id)
    {
     window.document.getElementById(f-id).focus();
    }
    -->
    </script>
    Body tag
    Code:
    <body onload="focusField(text)">
    Form tag
    Code:
    <form>
    <input type="text" id="text" />
    </form>
    Try that, 'text' being the ID of the field you want focused onload. Not tested, but I used something like this a long time ago...
    BWiz :: Happy Coding!
    2006
    2007 2008 2009
    2010 2011
    Irrational numbers make no sense.

  • #3
    Regular Coder
    Join Date
    May 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You meant
    Code:
    <body onload="focusField('text')">
    Or simply use this:
    Code:
    <body onload="document.getElementById('sid').focus()">
    
    <input type="text" id="sid" />


  •  

    Posting Permissions

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