I want to create the following behavior in IE9:
Clicking on the textbox will select the text from the textbox. Clicking on it again will unselect the text.
I tried the following from this linK: http://www.codingforums.com/showthread.php?t=105530
var x = 2;
function selectIt(obj)
{
if (x % 2 == 0)
{
obj.select();
}
else
{
if (document.selection)
{
document.selection.empty();
obj.blur();
}
else
{
window.getSelection().removeAllRanges();
}
}
obj.focus();
x++;
}
I also used this: http://jsfiddle.net/HmQxZ/1/
But the above solutions have weird behaviors when applied to several textboxes. What is the best way to approach this kind of problem. Is it possible to do this without using a global variable?
UPDATE:
The fiddle works in Chrome. But it does not work in IE9. In IE9, the text is selected but when you click on the textbox again, the text is not unselected/unhighlighted. In Chrome, the second click unselects/unhighlights the text.
Thank you.