Captain Comic Captain Comic - 7 months ago 81
Javascript Question

Inserting text after cursor position in text areа

The script below inserts text to the end of text area. I need to change to
insert text after current cursor position in the text area.

var imageLoc = prompt('Enter the Image URL:');
if ( imageLoc ) {
$('#comment').val($('#comment').val() + '[img]' + imageLoc + '[/img]');
return false;


You may checkout this answer. The insertAtCaret jquery plugin seems very nice.