I work with an auto-delivery code. setSelectionRange() used to select the text completed in the oninput event oninput . It works at least in Firefox 14, but not in Chrome (6, 17).
A simplified code snippet showing the problem is as follows:
<input type='text' oninput='select()' />
function select(e){ var s = this.value; if (s.length) this.setSelectionRange(s.length-1, s.length); }
I debugged the code in chrome, and it turned out that the text was selected first immediately after running setSelectionRange() , but the selection disappeared later.
If I bind the handler to onclick instead of oninput , for example:
<input type='text' onclick='select()' />
then both browsers work fine.
Can someone please give me some tips to do a select job in Chrome?
bigbug
source share