Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent tab text highlight / disable tab text selection

Here's a sample form:

<form action="#" method="post">
  Name:<br />
  <input type="text" name="name" value="your name" /><br />

  E-mail:<br />
  <input type="text" name="mail" value="your email" /><br />

  <input type="submit" value="Send"> 
</form>

When you tab to a text input, the value gets highlighted. How can it be disabled?

Any help is appreciated!

Mike

like image 433
Mori Avatar asked Jan 31 '26 01:01

Mori


1 Answers

var $yourInput;

$yourInput = $("#your_input");

setTimeout(function() {
  return $yourInput.selectRange($yourInput.val().length, $yourInput.val().length);
}, 10);

selectRange function you can find here: jQuery Set Cursor Position in Text Area

like image 136
Evsyukov Mikhail Avatar answered Feb 02 '26 19:02

Evsyukov Mikhail



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!