/ Published in: JavaScript
cross-browser way to select all text in a form element, via Jason on Stack Overflow
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function selectText(element) { var doc = document; var text = doc.getElementById(element); if (doc.body.createTextRange) { // ms var range = doc.body.createTextRange(); range.moveToElementText(text); range.select(); } else if (window.getSelection) { // moz, opera, webkit var selection = window.getSelection(); var range = doc.createRange(); range.selectNodeContents(text); selection.removeAllRanges(); selection.addRange(range); } }