Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically disable auto-select on <input type=text> elements?

Then the user uses TAB or SHIFT-TAB to "jump" to a certain text-box and that text-box happens to have a value in it, then that value will be auto-selected. I would like to disable this behavior.

I assume that can be done inside the focusin event handler:

$("input:text").focusin(function() {
    // "un-select" the value and place the text-cursor
    // at the beginning or end of the value
});
like image 317
Šime Vidas Avatar asked Aug 22 '26 03:08

Šime Vidas


1 Answers

$(function() {
    $('input').bind('focus', function(e) {
       return false;
    });
});

Using jQuery 1.4.3+ you can use the shortcut version:

$(function() {
    $('input').bind('focus', false);
});

Example: http://www.jsfiddle.net/P8LDB/

like image 93
jAndy Avatar answered Aug 23 '26 16:08

jAndy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!