Hi, I need help replacing text in a textarea, specifically creating a link tag around a piece of text (Exactly like the "insert link" button on this page) I've had trouble finding a cross-browser solution, but so far I can select the text successfully but just can't figure out how to replace it: function insert_link(){ var linktext; var txtarea = document.getElementById('newstext'); linktext = (txtarea.value).substring(txtarea.selectionStart,txtarea.selectionEnd); if (linktext == '') { alert("Please select some text for your link"); } else { var linkurl = window.prompt('Please enter the URL of the link', 'http://'); var htmllink = "<a href='" + linkurl + "'>" + linktext + "</a>"; //How do I insert the html back into the textarea? } } Code (markup): Thanks for your help
Just want to wrap html tags around some text: So replace this: Link Text with this: <a href='http://www.link.com'>Link Text</a>
See this page www dot massless dot org/mozedit/ There you can find cross browser textarea editor and answer to your question.