Captain Comic Captain Comic - 1 month ago 23
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.

jQuery(document).ready(function($){
$('#addCommentImage').click(function(){
var imageLoc = prompt('Enter the Image URL:');
if ( imageLoc ) {
$('#comment').val($('#comment').val() + '[img]' + imageLoc + '[/img]');
}
return false;
});
});

Answer

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