Helpful Information
 
 
Category: Web Design
cursor postion in a form field

Hi,
I've been searching all day, trying to find a solution for a problem that I am having.

What I would like to do is capture the position of the cursor in a textarea onBlur. When a user fills out and completes a second field within the same form, I would like to append the value of the second form to the location returned onBlur from the textarea. I can easily append to the end of the textarea using a simple javascript function, however inserting values into user defined locations in the textarea seems impossible. A DHTML drag and drop solution would be even better, but a solution for this seems even more elusive.

Has anyone ever accomplished this, or know of any possible directions to head?

Any help would be greatly appreciated -

Thanks -

I figured I'd bump this post since I'm having the same issue right now. I know it's a 4 year old thread (but hopefully that means it's been solved by now :D ) Anyways thanks in advance. If you know of A solution (or even if it's possible) please let me know. Thanks

-MBirchmeier

I found this at http://www.alexking.org/blog/index.php?p=286 for anyone that was interrested




function insertAtCursor(myField, myValue) {
//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
} else {
myField.value += myValue;
}
}










privacy (GDPR)