Micro Niche Builder
Closed Thread
Results 1 to 7 of 7

Thread: Setting focus on textbox

  1. #1

    Default Setting focus on textbox

    I have a login form when I load is I have to click on textbox to type into it. What I want is when page load completed focus should be in username text boxes. How can I do it using javascript?


  2. SEO Software

  3. #2

    Default

    This is quite easy - all you have to do is use the .focus() method. Include a <script> tag immediately after you write your textarea tag like this:

    Code:
    <textarea id="textbox"></textarea>
    <script type="text/javascript">
      document.getElementById("textbox").focus();
    </script>
    Likewise, you can use it on input fields as well:

    Code:
    <input id="myinput">
    <script type="text/javascript">
      document.getElementById("myinput").focus();
    </script>
    Make sure you include your <script> tag AFTER your input fields; this is important because you can't call a reference to an object if it doesn't exist, so you must create the object in the first place.

    Mike

  4. #3

    Default

    if you wants to focus on the textbox that plese go on coding window in vb.net than write in textbox1.focus

    in vb.net we can do it
    code:
    button_click events
    textbox1.text=focus
    end sub

  5. #4

    Default

    to set focus on the paritcular textbox, we have to folle the code :

    TextBox1.focus()

  6. #5

    Default

    this is very easy.

    u can do it in following way.

    Code:
    <html>
    <body onload="document.f1.t1.focus();">
    <form name="f1">
    <input type="text" name="t1"  value="">
    <form>
    </body>
    </html>
    or make separate function

    Code:
    <html>
    
    <script language="javascript">
    function fun()
    {
    	document.f1.t1.focus();
    }
    </script>
    
    <body onload="fun">
    <form name="f1">
    <input type="text" name="t1"  value="" >
    <form>
    </body>
    </html>

  7. #6

    Unhappy

    Quote Originally Posted by mburt View Post
    This is quite easy - all you have to do is use the .focus() method. Include a <script> tag immediately after you write your textarea tag like this:

    Code:
    <textarea id="textbox"></textarea>
    <script type="text/javascript">
      document.getElementById("textbox").focus();
    </script>
    Likewise, you can use it on input fields as well:

    Code:
    <input id="myinput">
    <script type="text/javascript">
      document.getElementById("myinput").focus();
    </script>
    Make sure you include your <script> tag AFTER your input fields; this is important because you can't call a reference to an object if it doesn't exist, so you must create the object in the first place.

    Mike
    hi mrbut......
    i tried the way which you have post in your reply...
    but still getting some problem...
    dont know why....
    just cheak the once.....
    is that having any error or i am doing any mistake......?

  8. #7

    Default

    Its pretty simple like what yahoo is doing while you login into their email system. You can easily view their source too.

    document.getElementById("inputb").focus();

    Hope it helps

Closed Thread

Tags for this Thread

Bookmarks

Posting Permissions

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