user2901740
user2901740

Reputation: 1571

Appending values to textarea with jquery

I'm trying to append the value from dropdown to textarea, This is working, I can add value but when I make changes on textarea, I can't add anymore when I edit the text area..

$('#addWord').click(function() {
   $('#textarea').append($('#selectbox').val() + ", ");
});

Upvotes: 0

Views: 78

Answers (2)

rgbflawed
rgbflawed

Reputation: 2137

You can treat a textarea like any other input and use val()

$('#addWord').click(function() {
   $('#textarea').val($('#textarea').val()+" "+$('#selectbox').val());
});

Working example: http://jsfiddle.net/BwV9F/

Upvotes: 1

CRABOLO
CRABOLO

Reputation: 8793

Try it using .text() instead of .append()

$('#addWord').click(function() {
   $('#textarea').text($('#selectbox').val() + ", ");
});

Upvotes: 2

Related Questions