SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Onselect

  1. #1
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Onselect

    I have a text element at form with a default value.
    I want, when user using tab goes to that text input not to select the text that it has, just the cursor go after the last character of the text.
    I hope I were understood.
    How can I do it?
    Dimis

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Give us a link to your test page and we'll take a look.

  3. #3
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Tab

    Suppose that code

    Code:
    <form action="">
    <input type="text" >
    <input type="text" name="some" value="something" >
    <input type="submit" />
    </form>
    User using tab may go to one element of the form to another, I want when
    Code:
    <input type="text" name="some" value="something" >
    is selected ,the text that it has, not to be selected.
    That value is necessary to add to the value of this text at database.
    If it can not be done, I may add this at the value of that text later.
    Dimis

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I understood the question. I just wondered if you might actually experiment with it yourself.

    Oh well. I give up. This is the only thing I could come up with. I don't know why I couldn't get the DOM range technique to work in FF.
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <script type='text/javascript'>
    window.onload = function()
    {
      var t = document.forms['f1'].t1;
      t.focus();
      t = document.forms['f1'].t2;
      t.onfocus = function()
      {
        if (this.createTextRange) { // IE6, Op9
          var v = this.value;
          var r = this.createTextRange();
          r.moveStart('character', v.length);
          r.select();
        }
        else { // FF1.0.2
          window.setTimeout(
            function() {
              var t = document.forms['f1'].t2;
              var v = t.value;
              t.value = v + ' ';
              t.value = v;
            },
            50
          );
        }
      }
    }
    </script>
    </head>
    <body>
    
    <form name='f1'>
    <input name='t1' type='text' value='t1'>
    <input name='t2' type='text' value='t2'>
    </form>
    
    </body>
    </html>
    Last edited by MikeFoster; Sep 12, 2006 at 08:04.

  5. #5
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Jscript

    Thanks, It is ok for me.


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
  •