Cancel selected text in javascript, now compatible with all major browsers:
if (document.selection) {
document.selection.empty();
} else if (window.getSelection) {
window.getSelection().removeAllRanges();
}
For unselecting the text in the text box (input, textarea), this method will have some problems.
But there is also a way, record the value in the text box, and then Clear it and reassign it. The method is a bit confusing, but it is compatible with all browsers.