0

Looking for a solution that works for all browsers including on iPad/iPhone. I have reviewed the past posting for this question, and the one as follows is working all fine, except that it is not working on IE:

$("input[type='text'], textarea, input[type='password'], input[type='number']").live('mouseup', function(e) {
    e.preventDefault();
});

$("input[type='text'], textarea, input[type='password'], input[type='number']").live('focus', function() {
    this.setSelectionRange(0, 9999);
});​
VisioN
  • 143,310
  • 32
  • 282
  • 281
  • Just as a side note, .live is now deprecated, and you should use jQuery .on – Chris Dixon Sep 04 '12 at 08:10
  • What is the point of trying to prevent the default action of `mouseup`? And, please describe what you are trying to accomplish with your code. Just posting code and saying it isn't working doesn't tell us what you're trying to do. – jfriend00 Sep 04 '12 at 08:29
  • this is a belated follow up to the following: http://stackoverflow.com/questions/9924506/selecting-text-on-focus-using-jquery-not-working-in-iphone-ipad-browsers which should give all background info of this issue. – user1045358 Sep 04 '12 at 15:25
  • 2
    I also found out a solution that we need to add an onclick function as follows: $("input[type=text]").live('click', function() { $(this).select(); this.setSelectionRange(0, 9999); }); – user1045358 Sep 04 '12 at 15:28
  • Actually, this above comment from user1045358 was the only solution that worked for me for the iPhone/iPad! Maybe this should be the answer and upvoted... – Beat Rupp Oct 12 '12 at 13:40

1 Answers1

0

The following code worked well for me:

$("input[type=text]").live('click', function() {
    $(this).select();
    this.setSelectionRange(0, 9999);
});

However this while the simplest solution has the downside that it doesn't pre select a text field when navigating with the keyboard. An alternative for this particular issue can be found at: Looking for a better workaround to Chrome select on focus bug

Note: this answer is from comment 4 on the original question.

Community
  • 1
  • 1