Jump to content

How To Keep Certain Text Selected/focussed In Textarea


wilsonf1

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...