// code for IE var textarea = document.getElementById("textarea"); if (document.selection) { textarea.focus(); var sel = document.selection.createRange(); // alert the selected text in textarea alert(sel.text); // Finally replace the value of the selected text // with this new replacement one sel.text = '' + sel.text + ''; } // code for Mozilla var textarea = document.getElementById("textarea"); var len = textarea.value.length; var start = textarea.selectionStart; var end = textarea.selectionEnd; var sel = textarea.value.substring(start, end); // This is the selected text and alert it alert(sel); var replace = '' + sel + ''; // Here we are replacing the selected text with this one textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
Thursday, August 19, 2010
How to replace selected textarea value using javascript
Subscribe to:
Post Comments (Atom)
5 Strategies for Getting More Work Done in Less Time
Summary. You’ve got more to do than could possibly get done with your current work style. You’ve prioritized. You’ve planned. You’ve dele...
-
Imagine going to work everyday and facing a colleague who does not respect you or having to work with someone who was constantly underminin...
-
Sometimes just to get a quick success build you might need to disable/ignore/skip some of the munit test cases. you can do you by double ...
-
Install ActiveMQ Step 1: Download Apache Active MQ 5.x.x (5.15.8 Latest Version Up to Feb 2019) Step 2: Install ActiveMQ Run the Active...
Very wonderful and informative piece of content you have shared. To learn more about Java from beginning and make career as a programmer, get enroll at Online Java Course in Kolkata, Delhi. Noida, Alwar, Pune and in many other cities of India.
ReplyDelete