select all in every ASP.NET textbox upon focus

I love this little bit of jQuery code...in IE.

$(document).ready(function() {

   // Add this behavior to all text fields
   $('input[type=text]').focus(function() {
      // Select field contents
      this.select();
   });

For the page I'm working on, I really like this behavior.  If you select a textbox (INPUT type=text), this bit of code selects all text in that box, ready for you to delete it or replace it, whatever.

Problem is, this doesn't work in Firefox.  How do I modify it so that it works in both IE and Firefox?

I'm only interested in meta-code like this, run it once and that's it.  No adding code per-each-control.  Don't want that.  This is behavior I want attached to every single enabled textbox on my page.  Ideally, I just want to modify this bit of code to make it work.

Thanks!
bamapieAsked:
Who is Participating?
 
leakim971PluritechnicianCommented:
try this : http://jsfiddle.net/tzpay/
$(':text').focus(function() {
    setTimeout(new Function( "$(':text:eq(" +  $(this).index(":text") + ")').select()" ), 50 );
});

Open in new window

0
 
bamapieAuthor Commented:
I'm a dope.  Still not getting this in Firefox.  I stuck an alert() at the end of your code that you're using in that setTimeout(), and I never see it in FF but do in IE.

But you know, it may be a 3rd-party tool I'm using that prevents non-numeric text entry in this textbox.

But then, you'd think if it's interfering, it would interfere with IE too, not just FF.

Crap.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.