Q:

Add text to textarrea issue using jquery

There are times tha i feel so frustrated when trying to do simple things with Jquery.
I have a textarea where user can write own things but can also chose from some predefined phrases and add them too
so html looks like
<textarea id="id_text"></textarea>
<div id="predef-phrases>
    <input type="checkbox"><label>checkbox1</label> 
    <input type="checkbox"><label>checkbox2</label>
    <input type="checkbox"><label>checkbox3</label>
    <input type="checkbox"><label>checkbox4</label>     
</div>
<input type="button" id="add" name="add" value="Add phrases" />

and the jquery is like this:
$(document).read(function(){
      $("#add").click(function(){
        $("#predef-phrases input[type=checkbox").each(function(i, checkbox){
            if($(checkbox).is(":checked")){
                text_value = $("#id_text").val();
                checkbox_text = $(checkbox).next('label').text();
                $("#id_text").append(checkbox_text+'\n');

            }
        });
    });
});

Everything works fine up until the user types some text. Then the predefined phrases are not appended in textarea when user presses the add button. Am i missing something?

A:

Don't use append, which would only change the "initial" value, but directly change the value :
$("#id_text")[0].value += checkbox_text+'\n';

If you prefer, you may also use the val function :
$("#id_text").val(function(_,text){ return text+checkbox_text+'\n'});

But you also have errors in your HTML (missing closing quote) and in your selector (missing closing brace). Here's a fixed code.

