Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4

Thread: setting focus

  1. #1
    Junior Member
    Join Date
    Nov 2003
    Posts
    6
    Member #
    3956
    can someone pls give me a hint how i can set the focus into a particular field of a form. i.e. for example i would like that when a user clicks the "reset button", i would like that the first field of the form will get the focus.

    thx for your help!

  2.  

  3. #2
    Senior Member nocloset's Avatar
    Join Date
    Sep 2003
    Posts
    108
    Member #
    3228
    The code below is stolen from W3Schools.com (http://www.w3schools.com/js/js_form.asp). Hope it helps.

    <html>
    <head>
    <script type="text/javascript">
    function setfocus()
    {
    document.forms[0].field.focus()
    }
    </script>
    </head>
    <body>
    <form>
    <input type="text" name="field" size="30">
    <input type="button" value="Get Focus" onclick="setfocus()">
    </form>
    </body>
    </html>

  4. #3
    Senior Member skrlin's Avatar
    Join Date
    Apr 2003
    Location
    Illinois
    Posts
    562
    Member #
    1063
    This also applies to windows.

    EX:
    PHP Code:
    <html>
    <
    head>
     <
    title>Window Focus Example</title>
     <
    script type="text/javascript">
      var 
    myWin window.open(); // opens new window
      
    myWin.document.write('new window'); // writes text to new window
      
    self.focus(); // brings first window back into focus

      
    function myWinFocus() {
       
    /* this next line waits 5 seconds... */
       
    setTimeout('myWin.focus()',5000); // then focuses the window you opened
      
    }
     
    </script>
    </head>
    <body onLoad="myWinFocus()">
     <!-- some html stuff here  -->
    </body>
    </html> 
    - Brian

  5. #4
    Junior Member
    Join Date
    Nov 2003
    Posts
    6
    Member #
    3956
    thx for your information!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:25 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com