[jQuery] Re: Position cursor at end of textbox?

2008-07-08 Thread Brian J. Fink

Please note: This discussion group is malfunctioning and you must open
quoted text in order to read the last line of the previous post. The
last tow lines should be

 });
});


If you do not copy the second }); my code will fail.



On Jul 8, 2:26 pm, "Brian J. Fink" <[EMAIL PROTECTED]> wrote:
> This is the best I can come up with. I wanted to catch the onselect
> event, but for some reason Safari won't respond. (Didn't want to keep
> using a timeout. It's a hack, but it works.) I reduced the length of
> the timeout to 0 milliseconds, and I cleaned up the call by passing
> the this object as a parameter. I also changed the moveStart for IE to
> a collapse instead.
>
> $(function() {
>  $(':text').focus(function() {
>   if (this.setSelectionRange) /* DOM */
>   {
>setTimeout(function(t) { /* hack for select delay */
> t.setSelectionRange(t.value.length,t.value.length);
>},0,this);
>   }
>   else if (this.createTextRange) /* IE */
>   {
>r=this.createTextRange();
>r.collapse(false);
>r.select();
>   }
>  });
>
> });


[jQuery] Re: Position cursor at end of textbox?

2008-07-08 Thread Brian J. Fink

This is the best I can come up with. I wanted to catch the onselect
event, but for some reason Safari won't respond. (Didn't want to keep
using a timeout. It's a hack, but it works.) I reduced the length of
the timeout to 0 milliseconds, and I cleaned up the call by passing
the this object as a parameter. I also changed the moveStart for IE to
a collapse instead.

$(function() {
 $(':text').focus(function() {
  if (this.setSelectionRange) /* DOM */
  {
   setTimeout(function(t) { /* hack for select delay */
t.setSelectionRange(t.value.length,t.value.length);
   },0,this);
  }
  else if (this.createTextRange) /* IE */
  {
   r=this.createTextRange();
   r.collapse(false);
   r.select();
  }
 });
});


[jQuery] Re: Position cursor at end of textbox?

2008-07-03 Thread Brian J. Fink

OK, I was a little premature in my judgment. But why add a new
function to jQuery when it will only be used once in your code? That's
kind of silly.

On Jul 3, 10:58 am, h3 <[EMAIL PROTECTED]> wrote:
> $.extend($.fn, {
> selectRange: function(start, end) {
> // use only the first one since only one input can be
> focused
> if ($(this).get(0).createTextRange) {
> var range = $(this).get(0).createTextRange();
> range.collapse(true);
> range.moveEnd('character',   end);
> range.moveStart('character', start);
> range.select();
> }
> else if ($(this).get(0).setSelectionRange) {
> $(this).focus().get(0).setSelectionRange(start, end);
> }
> return $(this);
> }
>
> });
>
> I think it's pretty much the best crossbrowser solution you will find.
>
> $('input').selectRange(0,0) to reset the carret position, to position
> it at the end you will need to get length of the input's value.. you
> just made me think
> I could add support for -1, thanks :D
>
> ~h
>
> On Jul 2, 2:55 pm, Paul Malan <[EMAIL PROTECTED]> wrote:
>
> > By default it seems browsers select all the text in a textbox when it
> > gains focus by way of a tab-press.  I would like the cursor to be
> > positioned at the end of any existing text in the input, instead.  The
> > examples I'm turning up on Google don't work and seem needlessly
> > complex, and since jQuery simplifies everything else I used to hate
> > about Javascript, I thought I'd see if there's a simple way to
> > position the cursor in a text input box on focus.  Is it doable?
>
> > Thanks...


[jQuery] Re: Position cursor at end of textbox?

2008-07-03 Thread Brian J. Fink

Returns error: $(this).caret is not a function.
The function must be part of the plugin you alluded to.

On Jul 2, 8:23 pm, spicyj <[EMAIL PROTECTED]> wrote:
> This might be helpful:
>
> http://pastie.org/226790// shamelessly stolen from the Masked Input
> plugin
>
> $(":text").bind("focus", function() {
>   $(this).caret(this.value.length);
>
> });
>
> Not tested, so I don't know if it works, but it might.


[jQuery] Re: Position cursor at end of textbox?

2008-07-03 Thread Brian J. Fink

Bah! What's with the $(this).get(0) when all you need is the this
keyword from JavaScript?
Oh, and by the way, Your solution would disable selection entirely. I
don't think Paul had in mind to kill a flea with a sledgehammer!

On Jul 3, 10:58 am, h3 <[EMAIL PROTECTED]> wrote:
> $.extend($.fn, {
> selectRange: function(start, end) {
> // use only the first one since only one input can be
> focused
> if ($(this).get(0).createTextRange) {
> var range = $(this).get(0).createTextRange();
> range.collapse(true);
> range.moveEnd('character',   end);
> range.moveStart('character', start);
> range.select();
> }
> else if ($(this).get(0).setSelectionRange) {
> $(this).focus().get(0).setSelectionRange(start, end);
> }
> return $(this);
> }
>
> });
>
> I think it's pretty much the best crossbrowser solution you will find.
>
> $('input').selectRange(0,0) to reset the carret position, to position
> it at the end you will need to get length of the input's value.. you
> just made me think
> I could add support for -1, thanks :D
>
> ~h
>
> On Jul 2, 2:55 pm, Paul Malan <[EMAIL PROTECTED]> wrote:
>
> > By default it seems browsers select all the text in a textbox when it
> > gains focus by way of a tab-press.  I would like the cursor to be
> > positioned at the end of any existing text in the input, instead.  The
> > examples I'm turning up on Google don't work and seem needlessly
> > complex, and since jQuery simplifies everything else I used to hate
> > about Javascript, I thought I'd see if there's a simple way to
> > position the cursor in a text input box on focus.  Is it doable?
>
> > Thanks...


[jQuery] Re: Position cursor at end of textbox?

2008-07-03 Thread Brian J. Fink

There's a $.caret()?

On Jul 2, 8:23 pm, spicyj <[EMAIL PROTECTED]> wrote:
> This might be helpful:
>
> http://pastie.org/226790// shamelessly stolen from the Masked Input
> plugin
>
> $(":text").bind("focus", function() {
>   $(this).caret(this.value.length);
>
> });
>
> Not tested, so I don't know if it works, but it might.


[jQuery] Re: Position cursor at end of textbox?

2008-07-03 Thread h3

$.extend($.fn, {
selectRange: function(start, end) {
// use only the first one since only one input can be
focused
if ($(this).get(0).createTextRange) {
var range = $(this).get(0).createTextRange();
range.collapse(true);
range.moveEnd('character',   end);
range.moveStart('character', start);
range.select();
}
else if ($(this).get(0).setSelectionRange) {
$(this).focus().get(0).setSelectionRange(start, end);
}
return $(this);
}
});

I think it's pretty much the best crossbrowser solution you will find.

$('input').selectRange(0,0) to reset the carret position, to position
it at the end you will need to get length of the input's value.. you
just made me think
I could add support for -1, thanks :D

~h

On Jul 2, 2:55 pm, Paul Malan <[EMAIL PROTECTED]> wrote:
> By default it seems browsers select all the text in a textbox when it
> gains focus by way of a tab-press.  I would like the cursor to be
> positioned at the end of any existing text in the input, instead.  The
> examples I'm turning up on Google don't work and seem needlessly
> complex, and since jQuery simplifies everything else I used to hate
> about Javascript, I thought I'd see if there's a simple way to
> position the cursor in a text input box on focus.  Is it doable?
>
> Thanks...


[jQuery] Re: Position cursor at end of textbox?

2008-07-02 Thread spicyj

This might be helpful:

http://pastie.org/226790 // shamelessly stolen from the Masked Input
plugin

$(":text").bind("focus", function() {
  $(this).caret(this.value.length);
});

Not tested, so I don't know if it works, but it might.


[jQuery] Re: Position cursor at end of textbox?

2008-07-02 Thread Erik Beeson
No worries. Thanks for taking the time to test it :) Scoping is probably one
of the most unobvious aspects of JavaScript.

--Erik


On 7/2/08, Brian J. Fink <[EMAIL PROTECTED]> wrote:
>
>
> My apologies, Erik. Yours is the superior method. I must have been
> remembering the behavior of IE5.
>
>
> On Jul 2, 8:12 pm, "Erik Beeson" <[EMAIL PROTECTED]> wrote:
>
> > Ick! Global variables and eval'd code! How about (untested, logic should
> be
> > unchanged):
> >
> > $(function() {
> > $(':text').bind('focus', function() {
> > var o = this;
> > if(o.setSelectionRange) { /* DOM */
> > setTimeout(function()
> > {o.setSelectionRange(o.value.length,o.value.length);}, 2);
> > } else if(o.createTextRange) {/* IE */
> > var r = o.createTextRange();
> > r.moveStart('character', o.value.length);
> > r.select();
> > }
> > });
> >
> > });
> >
> > Adds an anonymous function, which adds a function call, but saves an eval
> > and doesn't require a global variable, which is potentially problematic.
> >
> > --Erik
> >
>
> > On 7/2/08, Brian J. Fink <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> > > And I checked my code again. It DOES work on FF3, FF2, and IE7.
> >
> > > On Jul 2, 5:37 pm, Paul Malan <[EMAIL PROTECTED]> wrote:
> > > > Thanks for the code.  It doesn't work for me--still when I tab into a
> > > > textbox in either IE7 or FF3 the content is selected and the cursor
> > > > isn't positioned at the end of the text, even when I pull out
> > > > everything but this function and two textboxes to test.
> >
> > > > I think I may just give up--it was a minor detail and not requested
> by
> > > > the users.  Bugs me, though.  Seems like it shouldn't be so
> tricksy...
> >
> > > > On Jul 2, 3:12 pm, "Brian J. Fink" <[EMAIL PROTECTED]> wrote:
> >
> > > > > There may be a jQuery way to do this, but I don't know what it is.
> >
> > > > > However, I do know 2 ways to accomplish this: one DOM way, one IE
> way.
> > > > > Both methods must be employed.
> >
> > > > > $(function() {
> > > > >  $('input[type="text"]').bind('focus',function() {
> > > > >   window.o=this;
> > > > >   if (o.setSelectionRange) /* DOM */
> > > >
> >setTimeout('o.setSelectionRange(o.value.length,o.value.length)',2);
> > > > >   else if (o.createTextRange) /* IE */
> > > > >   {
> > > > >var r=o.createTextRange();
> > > > >r.moveStart('character',o.value.length);
> > > > >r.select();
> > > > >   }
> > > > >  });
> >
> > > > > });
> >
> > > > > On Jul 2, 2:55 pm, Paul Malan <[EMAIL PROTECTED]> wrote:
> >
> > > > > > By default it seems browsers select all the text in a textbox
> when it
> > > > > > gains focus by way of a tab-press.  I would like the cursor to be
> > > > > > positioned at the end of any existing text in the input,
> > > instead.  The
> > > > > > examples I'm turning up on Google don't work and seem needlessly
> > > > > > complex, and since jQuery simplifies everything else I used to
> hate
> > > > > > about Javascript, I thought I'd see if there's a simple way to
> > > > > > position the cursor in a text input box on focus.  Is it doable?
> >
> > > > > > Thanks...
>


[jQuery] Re: Position cursor at end of textbox?

2008-07-02 Thread Brian J. Fink

My apologies, Erik. Yours is the superior method. I must have been
remembering the behavior of IE5.

On Jul 2, 8:12 pm, "Erik Beeson" <[EMAIL PROTECTED]> wrote:
> Ick! Global variables and eval'd code! How about (untested, logic should be
> unchanged):
>
> $(function() {
> $(':text').bind('focus', function() {
> var o = this;
> if(o.setSelectionRange) { /* DOM */
> setTimeout(function()
> {o.setSelectionRange(o.value.length,o.value.length);}, 2);
> } else if(o.createTextRange) {/* IE */
> var r = o.createTextRange();
> r.moveStart('character', o.value.length);
> r.select();
> }
> });
>
> });
>
> Adds an anonymous function, which adds a function call, but saves an eval
> and doesn't require a global variable, which is potentially problematic.
>
> --Erik
>
> On 7/2/08, Brian J. Fink <[EMAIL PROTECTED]> wrote:
>
>
>
> > And I checked my code again. It DOES work on FF3, FF2, and IE7.
>
> > On Jul 2, 5:37 pm, Paul Malan <[EMAIL PROTECTED]> wrote:
> > > Thanks for the code.  It doesn't work for me--still when I tab into a
> > > textbox in either IE7 or FF3 the content is selected and the cursor
> > > isn't positioned at the end of the text, even when I pull out
> > > everything but this function and two textboxes to test.
>
> > > I think I may just give up--it was a minor detail and not requested by
> > > the users.  Bugs me, though.  Seems like it shouldn't be so tricksy...
>
> > > On Jul 2, 3:12 pm, "Brian J. Fink" <[EMAIL PROTECTED]> wrote:
>
> > > > There may be a jQuery way to do this, but I don't know what it is.
>
> > > > However, I do know 2 ways to accomplish this: one DOM way, one IE way.
> > > > Both methods must be employed.
>
> > > > $(function() {
> > > >  $('input[type="text"]').bind('focus',function() {
> > > >   window.o=this;
> > > >   if (o.setSelectionRange) /* DOM */
> > > >setTimeout('o.setSelectionRange(o.value.length,o.value.length)',2);
> > > >   else if (o.createTextRange) /* IE */
> > > >   {
> > > >var r=o.createTextRange();
> > > >r.moveStart('character',o.value.length);
> > > >r.select();
> > > >   }
> > > >  });
>
> > > > });
>
> > > > On Jul 2, 2:55 pm, Paul Malan <[EMAIL PROTECTED]> wrote:
>
> > > > > By default it seems browsers select all the text in a textbox when it
> > > > > gains focus by way of a tab-press.  I would like the cursor to be
> > > > > positioned at the end of any existing text in the input,
> > instead.  The
> > > > > examples I'm turning up on Google don't work and seem needlessly
> > > > > complex, and since jQuery simplifies everything else I used to hate
> > > > > about Javascript, I thought I'd see if there's a simple way to
> > > > > position the cursor in a text input box on focus.  Is it doable?
>
> > > > > Thanks...


[jQuery] Re: Position cursor at end of textbox?

2008-07-02 Thread Brian J. Fink

I believe setTimeouts work outside the scope of the function they are
called from. Test your way but I don't think it'll work.

On Jul 2, 8:12 pm, "Erik Beeson" <[EMAIL PROTECTED]> wrote:
> Ick! Global variables and eval'd code! How about (untested, logic should be
> unchanged):
>
> $(function() {
> $(':text').bind('focus', function() {
> var o = this;
> if(o.setSelectionRange) { /* DOM */
> setTimeout(function()
> {o.setSelectionRange(o.value.length,o.value.length);}, 2);
> } else if(o.createTextRange) {/* IE */
> var r = o.createTextRange();
> r.moveStart('character', o.value.length);
> r.select();
> }
> });
>
> });
>
> Adds an anonymous function, which adds a function call, but saves an eval
> and doesn't require a global variable, which is potentially problematic.
>
> --Erik
>
> On 7/2/08, Brian J. Fink <[EMAIL PROTECTED]> wrote:
>
>
>
> > And I checked my code again. It DOES work on FF3, FF2, and IE7.
>
> > On Jul 2, 5:37 pm, Paul Malan <[EMAIL PROTECTED]> wrote:
> > > Thanks for the code.  It doesn't work for me--still when I tab into a
> > > textbox in either IE7 or FF3 the content is selected and the cursor
> > > isn't positioned at the end of the text, even when I pull out
> > > everything but this function and two textboxes to test.
>
> > > I think I may just give up--it was a minor detail and not requested by
> > > the users.  Bugs me, though.  Seems like it shouldn't be so tricksy...
>
> > > On Jul 2, 3:12 pm, "Brian J. Fink" <[EMAIL PROTECTED]> wrote:
>
> > > > There may be a jQuery way to do this, but I don't know what it is.
>
> > > > However, I do know 2 ways to accomplish this: one DOM way, one IE way.
> > > > Both methods must be employed.
>
> > > > $(function() {
> > > >  $('input[type="text"]').bind('focus',function() {
> > > >   window.o=this;
> > > >   if (o.setSelectionRange) /* DOM */
> > > >setTimeout('o.setSelectionRange(o.value.length,o.value.length)',2);
> > > >   else if (o.createTextRange) /* IE */
> > > >   {
> > > >var r=o.createTextRange();
> > > >r.moveStart('character',o.value.length);
> > > >r.select();
> > > >   }
> > > >  });
>
> > > > });
>
> > > > On Jul 2, 2:55 pm, Paul Malan <[EMAIL PROTECTED]> wrote:
>
> > > > > By default it seems browsers select all the text in a textbox when it
> > > > > gains focus by way of a tab-press.  I would like the cursor to be
> > > > > positioned at the end of any existing text in the input,
> > instead.  The
> > > > > examples I'm turning up on Google don't work and seem needlessly
> > > > > complex, and since jQuery simplifies everything else I used to hate
> > > > > about Javascript, I thought I'd see if there's a simple way to
> > > > > position the cursor in a text input box on focus.  Is it doable?
>
> > > > > Thanks...


[jQuery] Re: Position cursor at end of textbox?

2008-07-02 Thread Erik Beeson
Ick! Global variables and eval'd code! How about (untested, logic should be
unchanged):

$(function() {
$(':text').bind('focus', function() {
var o = this;
if(o.setSelectionRange) { /* DOM */
setTimeout(function()
{o.setSelectionRange(o.value.length,o.value.length);}, 2);
} else if(o.createTextRange) {/* IE */
var r = o.createTextRange();
r.moveStart('character', o.value.length);
r.select();
}
});
});

Adds an anonymous function, which adds a function call, but saves an eval
and doesn't require a global variable, which is potentially problematic.

--Erik



On 7/2/08, Brian J. Fink <[EMAIL PROTECTED]> wrote:
>
>
> And I checked my code again. It DOES work on FF3, FF2, and IE7.
>
>
> On Jul 2, 5:37 pm, Paul Malan <[EMAIL PROTECTED]> wrote:
> > Thanks for the code.  It doesn't work for me--still when I tab into a
> > textbox in either IE7 or FF3 the content is selected and the cursor
> > isn't positioned at the end of the text, even when I pull out
> > everything but this function and two textboxes to test.
> >
> > I think I may just give up--it was a minor detail and not requested by
> > the users.  Bugs me, though.  Seems like it shouldn't be so tricksy...
> >
> > On Jul 2, 3:12 pm, "Brian J. Fink" <[EMAIL PROTECTED]> wrote:
> >
> > > There may be a jQuery way to do this, but I don't know what it is.
> >
> > > However, I do know 2 ways to accomplish this: one DOM way, one IE way.
> > > Both methods must be employed.
> >
> > > $(function() {
> > >  $('input[type="text"]').bind('focus',function() {
> > >   window.o=this;
> > >   if (o.setSelectionRange) /* DOM */
> > >setTimeout('o.setSelectionRange(o.value.length,o.value.length)',2);
> > >   else if (o.createTextRange) /* IE */
> > >   {
> > >var r=o.createTextRange();
> > >r.moveStart('character',o.value.length);
> > >r.select();
> > >   }
> > >  });
> >
> > > });
> >
> > > On Jul 2, 2:55 pm, Paul Malan <[EMAIL PROTECTED]> wrote:
> >
> > > > By default it seems browsers select all the text in a textbox when it
> > > > gains focus by way of a tab-press.  I would like the cursor to be
> > > > positioned at the end of any existing text in the input,
> instead.  The
> > > > examples I'm turning up on Google don't work and seem needlessly
> > > > complex, and since jQuery simplifies everything else I used to hate
> > > > about Javascript, I thought I'd see if there's a simple way to
> > > > position the cursor in a text input box on focus.  Is it doable?
> >
> > > > Thanks...
>


[jQuery] Re: Position cursor at end of textbox?

2008-07-02 Thread Brian J. Fink

And I checked my code again. It DOES work on FF3, FF2, and IE7.

On Jul 2, 5:37 pm, Paul Malan <[EMAIL PROTECTED]> wrote:
> Thanks for the code.  It doesn't work for me--still when I tab into a
> textbox in either IE7 or FF3 the content is selected and the cursor
> isn't positioned at the end of the text, even when I pull out
> everything but this function and two textboxes to test.
>
> I think I may just give up--it was a minor detail and not requested by
> the users.  Bugs me, though.  Seems like it shouldn't be so tricksy...
>
> On Jul 2, 3:12 pm, "Brian J. Fink" <[EMAIL PROTECTED]> wrote:
>
> > There may be a jQuery way to do this, but I don't know what it is.
>
> > However, I do know 2 ways to accomplish this: one DOM way, one IE way.
> > Both methods must be employed.
>
> > $(function() {
> >  $('input[type="text"]').bind('focus',function() {
> >   window.o=this;
> >   if (o.setSelectionRange)     /* DOM */
> >    setTimeout('o.setSelectionRange(o.value.length,o.value.length)',2);
> >   else if (o.createTextRange)     /* IE */
> >   {
> >    var r=o.createTextRange();
> >    r.moveStart('character',o.value.length);
> >    r.select();
> >   }
> >  });
>
> > });
>
> > On Jul 2, 2:55 pm, Paul Malan <[EMAIL PROTECTED]> wrote:
>
> > > By default it seems browsers select all the text in a textbox when it
> > > gains focus by way of a tab-press.  I would like the cursor to be
> > > positioned at the end of any existing text in the input, instead.  The
> > > examples I'm turning up on Google don't work and seem needlessly
> > > complex, and since jQuery simplifies everything else I used to hate
> > > about Javascript, I thought I'd see if there's a simple way to
> > > position the cursor in a text input box on focus.  Is it doable?
>
> > > Thanks...


[jQuery] Re: Position cursor at end of textbox?

2008-07-02 Thread Brian J. Fink

Also be sure you have two sets of }); at the end of your function:

 });
});

The message displayed with the 2 of them separated, so the second one
was easy to miss.


On Jul 2, 5:37 pm, Paul Malan <[EMAIL PROTECTED]> wrote:
> Thanks for the code.  It doesn't work for me--still when I tab into a
> textbox in either IE7 or FF3 the content is selected and the cursor
> isn't positioned at the end of the text, even when I pull out
> everything but this function and two textboxes to test.
>
> I think I may just give up--it was a minor detail and not requested by
> the users.  Bugs me, though.  Seems like it shouldn't be so tricksy...
>
> On Jul 2, 3:12 pm, "Brian J. Fink" <[EMAIL PROTECTED]> wrote:
>
> > There may be a jQuery way to do this, but I don't know what it is.
>
> > However, I do know 2 ways to accomplish this: one DOM way, one IE way.
> > Both methods must be employed.
>
> > $(function() {
> >  $('input[type="text"]').bind('focus',function() {
> >   window.o=this;
> >   if (o.setSelectionRange)     /* DOM */
> >    setTimeout('o.setSelectionRange(o.value.length,o.value.length)',2);
> >   else if (o.createTextRange)     /* IE */
> >   {
> >    var r=o.createTextRange();
> >    r.moveStart('character',o.value.length);
> >    r.select();
> >   }
> >  });
>
> > });
>
> > On Jul 2, 2:55 pm, Paul Malan <[EMAIL PROTECTED]> wrote:
>
> > > By default it seems browsers select all the text in a textbox when it
> > > gains focus by way of a tab-press.  I would like the cursor to be
> > > positioned at the end of any existing text in the input, instead.  The
> > > examples I'm turning up on Google don't work and seem needlessly
> > > complex, and since jQuery simplifies everything else I used to hate
> > > about Javascript, I thought I'd see if there's a simple way to
> > > position the cursor in a text input box on focus.  Is it doable?
>
> > > Thanks...


[jQuery] Re: Position cursor at end of textbox?

2008-07-02 Thread Brian J. Fink

Funny, it worked for me on IE7. And FF2. I didn't test it on 3 yet.

BTW if you already have a $ or $(document).ready, you must take the
code inside the curly braces and insert that into it.

On Jul 2, 5:37 pm, Paul Malan <[EMAIL PROTECTED]> wrote:
> Thanks for the code.  It doesn't work for me--still when I tab into a
> textbox in either IE7 or FF3 the content is selected and the cursor
> isn't positioned at the end of the text, even when I pull out
> everything but this function and two textboxes to test.
>
> I think I may just give up--it was a minor detail and not requested by
> the users.  Bugs me, though.  Seems like it shouldn't be so tricksy...
>
> On Jul 2, 3:12 pm, "Brian J. Fink" <[EMAIL PROTECTED]> wrote:
>
> > There may be a jQuery way to do this, but I don't know what it is.
>
> > However, I do know 2 ways to accomplish this: one DOM way, one IE way.
> > Both methods must be employed.
>
> > $(function() {
> >  $('input[type="text"]').bind('focus',function() {
> >   window.o=this;
> >   if (o.setSelectionRange) /* DOM */
> >setTimeout('o.setSelectionRange(o.value.length,o.value.length)',2);
> >   else if (o.createTextRange) /* IE */
> >   {
> >var r=o.createTextRange();
> >r.moveStart('character',o.value.length);
> >r.select();
> >   }
> >  });
>
> > });
>
> > On Jul 2, 2:55 pm, Paul Malan <[EMAIL PROTECTED]> wrote:
>
> > > By default it seems browsers select all the text in a textbox when it
> > > gains focus by way of a tab-press.  I would like the cursor to be
> > > positioned at the end of any existing text in the input, instead.  The
> > > examples I'm turning up on Google don't work and seem needlessly
> > > complex, and since jQuery simplifies everything else I used to hate
> > > about Javascript, I thought I'd see if there's a simple way to
> > > position the cursor in a text input box on focus.  Is it doable?
>
> > > Thanks...


[jQuery] Re: Position cursor at end of textbox?

2008-07-02 Thread Paul Malan

Thanks for the code.  It doesn't work for me--still when I tab into a
textbox in either IE7 or FF3 the content is selected and the cursor
isn't positioned at the end of the text, even when I pull out
everything but this function and two textboxes to test.

I think I may just give up--it was a minor detail and not requested by
the users.  Bugs me, though.  Seems like it shouldn't be so tricksy...

On Jul 2, 3:12 pm, "Brian J. Fink" <[EMAIL PROTECTED]> wrote:
> There may be a jQuery way to do this, but I don't know what it is.
>
> However, I do know 2 ways to accomplish this: one DOM way, one IE way.
> Both methods must be employed.
>
> $(function() {
>  $('input[type="text"]').bind('focus',function() {
>   window.o=this;
>   if (o.setSelectionRange)     /* DOM */
>    setTimeout('o.setSelectionRange(o.value.length,o.value.length)',2);
>   else if (o.createTextRange)     /* IE */
>   {
>    var r=o.createTextRange();
>    r.moveStart('character',o.value.length);
>    r.select();
>   }
>  });
>
> });
>
> On Jul 2, 2:55 pm, Paul Malan <[EMAIL PROTECTED]> wrote:
>
> > By default it seems browsers select all the text in a textbox when it
> > gains focus by way of a tab-press.  I would like the cursor to be
> > positioned at the end of any existing text in the input, instead.  The
> > examples I'm turning up on Google don't work and seem needlessly
> > complex, and since jQuery simplifies everything else I used to hate
> > about Javascript, I thought I'd see if there's a simple way to
> > position the cursor in a text input box on focus.  Is it doable?
>
> > Thanks...


[jQuery] Re: Position cursor at end of textbox?

2008-07-02 Thread Brian J. Fink

There may be a jQuery way to do this, but I don't know what it is.

However, I do know 2 ways to accomplish this: one DOM way, one IE way.
Both methods must be employed.

$(function() {
 $('input[type="text"]').bind('focus',function() {
  window.o=this;
  if (o.setSelectionRange) /* DOM */
   setTimeout('o.setSelectionRange(o.value.length,o.value.length)',2);
  else if (o.createTextRange) /* IE */
  {
   var r=o.createTextRange();
   r.moveStart('character',o.value.length);
   r.select();
  }
 });
});


On Jul 2, 2:55 pm, Paul Malan <[EMAIL PROTECTED]> wrote:
> By default it seems browsers select all the text in a textbox when it
> gains focus by way of a tab-press.  I would like the cursor to be
> positioned at the end of any existing text in the input, instead.  The
> examples I'm turning up on Google don't work and seem needlessly
> complex, and since jQuery simplifies everything else I used to hate
> about Javascript, I thought I'd see if there's a simple way to
> position the cursor in a text input box on focus.  Is it doable?
>
> Thanks...