View Full Version : Cursor location

01-08-2007, 10:06 PM
Hi everybody,

The code written below is made with one of my previous codes. That was working on the selected texts. I just need it to be edited to Cursor location point. Basicly when someone clicks a button I want this prompt window appear and ask the client the name of the image. When they type and click ok then the code must write [img=valuenteredtoprompt] whereever the cursor is located in my text area. Here is the code to be edited. My text area code and how I call the script.

function addimage(id) {
var textEl = document.getElementById(id);
var selectedText = (document.all) ? document.selection.createRange().text : (textEl.value).substring(textEl.selectionStart, textEl.selectionEnd);
var name=prompt("Please enter image name","")
if (name!=null && name!="")
textEl.value = textEl.value.replace(selectedText, selectedText + "[img=" + name + "]");


<textarea name="aboutus" rows="6" cols="50"><%=ors.Fields("aboutus").value%></textarea>

<input type="button" value="Add Image" onClick="addimage('aboutus');" />

I will be glad if you can help...


01-08-2007, 10:36 PM
One problem I see is

<textarea name="aboutus" ...

needs to be

<textarea name="aboutus" id="aboutus" ...

otherwise your document.getElementById() will be null.


01-08-2007, 11:34 PM
Answer in your previous post