I have some checkboxes which generate text in a text area. I would like to user to be able to add or edit the generated text within the area, then move on to add more automatically generated text.

I'm having trouble "saving" any edits that are made. It seems that I can listen for changes in the textarea via the `$('textarea').change(function(){ set text variable to textarea value.` construct, but I keep returning the original values when additional checkboxes are selected.

My HTML:

```
<input type='checkbox' id='line1'>Some text
<br>
<input type='checkbox' id='line2'>more text
<br>
<input type='checkbox' id='line3'>even more text
<br>
<textarea id='output' placeholder='1st textarea' rows=10 cols=20></textarea>
<br>

```

The relevant bits of my text generating code:

```
var texts = {
    line1: 'some text',
    line2: 'more text',
    line3: 'even more text'
};

// temporary holder for checkbox id
var part_choice = null;

// new textarea variables
var first_text = $('#output').val();

// old text variable
var text_old = '';

// fill texts in the textbox
function print_text() {
    if (part_choice !== null) {
        first_text += texts[part_choice] + '\n';
        part_choice = null;
        $('#output').val(first_text);
    }
}

// Retain any manual edits within textarea
$('#output').change(function () {
    first_text = $('#output').val();
});

$('input:checkbox').change(function () {
    if ($(this).is(':checked')) {
        part_choice = $(this).attr('id');
        text_old = first_text;
        print_text();
    } else {
        var del = $(this).attr('id');
        text_old = first_text.replace(texts[del] + '\n', '');
        first_text = text_old;
        $('#output').val(text_old); // undo function, textarea = prior text
    }
});

```

**Now that the faulty code is fixed - A follow-up question**: I'd like to simulate a manual edit using jquery and a keypress trigger event. I'm able to execute a simulation of pressing the 'spacebar' in the textarea. This should save the textarea contents before the next item is selected, but it does not. Only a physical keypress seems to work? What gives?