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
  1. #1
    New Coder
    Join Date
    Aug 2003
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Place cusor in first position of textbox?

    Greetings to All,

    And of course many, many thank yous in advance.

    Okay, how can I place the cursor in the first position of a textbox that already contains data using an onMousedown() event?

    Any direction or input would be greatly appreciated.

    Again, many thanks,

    eck35

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    nice question... At first glance I was tempted to say... just use focus() method... later I saw that, if onmousedown the cursor places whereever between the selected intial value characters...

    Yet, I found out a phoney behaviour... If inserted an alert command, the cursor does place at the begining... This might not be a good answer to your question, but it might help you somehow...

    Code:
    <html>
    <head>
    <script>
    function bla(){
    document.forms[0].text.focus();
    alert('oak');
    }
    </script>
    </head>
    <body>
    <form>
      <input name ="text" type="text" value="oak" onmousedown="bla()">
    </form>
    </body>
    </html>
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by Kor
    nice question... At first glance I was tempted to say... just use focus() method... later I saw that, if onmousedown the cursor places whereever between the selected intial value characters...

    Yet, I found out a phoney behaviour... If inserted an alert command, the cursor does place at the begining... This might not be a good answer to your question, but it might help you somehow...

    Code:
    <html>
    <head>
    <script>
    function bla(){
    document.forms[0].text.focus();
    alert('oak');
    }
    </script>
    </head>
    <body>
    <form>
      <input name ="text" type="text" value="oak" onmousedown="bla()">
    </form>
    </body>
    </html>
    To do this (leave default value but place cursor prior) you can also use reset()

    EG:
    Code:
    <form>
      <input name ="text" type="text" value="oak" onfocus="reset();">
    </form>
    Or to remove the default value:
    Code:
    <html>
    <head>
    <script>
    function bla(){
    document.forms[0].text.value='';
    }
    </script>
    </head>
    <body>
    <form>
      <input name ="text" type="text" value="oak" onmousedown="bla();">
    </form>
    </body>
    </html>
    ....Willy

    Edit: Changed onmousedown back to onfocus.
    Sorry, I was using onfocus, then seen the op requested
    onmousedown. Changed it and then realized that didn't work.
    Last edited by Willy Duitt; 12-20-2003 at 05:17 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
    •