wilsonf1 Posted October 24, 2009 Report Share Posted October 24, 2009 i use the following function in my custom cms to highlight text and turn it into an anchor linkit works, however once its done the cursor seems to go to the start of the line in the textarea - i want to still be highlighting the text or at least have the cursor near it, would save me loads of time thanks!!!!! function CreateALink(xId) { // code for Mozilla var textarea = document.getElementById(xId); 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 = '<a href=\"\" title=\"' + sel + '\">' + sel + '</a>'; // Here we are replacing the selected text with this one textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len); } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now