Если у вас есть несколько текстовых областей, вы, вероятно, захотите сделать что-то подобное.
// any time a textarea gets focus, set the ID
$('textarea').focus(function(){
focusID = $(this).attr('id');
});
// when the button is clicked
$('input[type="button"]').click(function(){
// insert the value into the textarea
insertAtCaret(focusID,$(this).val())
});
Посмотрите мой пример на jsFiddle здесь
Проблема, с которой я столкнулся, заключалась в том, что при нажатии кнопки текстовая область теряла фокус, поэтому было трудно найти текстовую область, которая была в фокусе в момент нажатия кнопки.
EDIT
Я только что понял, что вы пытаетесь сделать это с помощью входных данных, новый jsFiddle здесь: http://jsfiddle.net/tVNDL/1/
// any time a input gets focus, set the ID
$('input').focus(function(){
focusID = $(this).attr('id');
});
// when the button is clicked
$('input[type="button"]').click(function(){
// insert the value into the textarea
insertAtCaret(focusID,$(this).val())
});