A table row is causing content adding to not work
<p>I have a piece of code below which works fine when it comes to adding text from a modal window into a textarea:</p>

<pre><code>&lt;script type="text/javascript"&gt;

var plusbutton_clicked;

function insertQuestion(form) {

    var $tbody = $('#qandatbl &gt; tbody'); 
    var $tr = $("&lt;tr class='optionAndAnswer' align='center'&gt;&lt;/tr&gt;");
    var $plusrow = $("&lt;td class='plusrow'&gt;&lt;/td&gt;");
    var $question = $("&lt;td class='question'&gt;&lt;/td&gt;");


    $('.questionTextArea').each( function() {

    var $this = $(this);
    var $questionText = $("&lt;textarea class='textAreaQuestion'&gt;&lt;/textarea&gt;").attr('name',$this.attr('name')+"[]")
                   .attr('value',$this.val());

    $question.append($questionText);

    });

        $('.plusimage').each( function() {

    var $this = $(this);
    var $plusimagerow = $("&lt;a onclick='return plusbutton(this);'&gt;&lt;img src='Images/plussign.jpg' width='30' height='30' alt='Look Up Previous Question' class='imageplus'/&gt;&lt;/a&gt;").attr('name',$this.attr('name')+"[]")
                   .attr('value',$this.val());

    $plusrow.append($plusimagerow);

    });

    $tr.append($plusrow);
    $tr.append($question);
    $tbody.append($tr); 

    form.questionText.value = "";

    $('.questionTextArea').val('');


}


function closewindow() {     

    $.modal.close(); 
    return false;
} 

$('.plusimage').live('click', function() {
    plusbutton($(this));
});


function plusbutton(plus_id) {
    // Set global info
    plusbutton_clicked = plus_id;
    // Display an external page using an iframe
    var src = "previousquestions.php";
    $.modal('&lt;iframe src="' + src + '" style="border:0;width:100%;height:100%;"&gt;');
    return false;
}


function addwindow(questionText) { 

    if(window.console) console.log();

    if($(plusbutton_clicked).attr('id')=='mainPlusbutton') { 
        $('#mainTextarea').val(questionText); 
        } else { 
            $(plusbutton_clicked).parent('td').next('td.question').find('textarea.textAreaQuestion').val(questionText);
            }

    $.modal.close(); 
    return false;
} 


&lt;/script&gt;
</code></pre>

<p>But the problem is that if I include this code below which I need into the <code>function insertQuestion(form) {</code>, then it stops the text adding into the textarea, why is it doing this?</p>

<pre><code>var $qid = $("&lt;td class='qid'&gt;" + qnum + "&lt;/td&gt;" );

...

$tr.append($qid);
</code></pre>

<p>$qid is the question number for each row, so everytime a row is added, it adds a question number by plus 1 each time.</p>

<p>Blow is the html code of where it appends the textarea from the top into a table row:</p>

<pre><code>&lt;table id="question"&gt;
&lt;tr&gt;
    &lt;th colspan="2"&gt;
        Question Number &lt;span class="questionNum"&gt;1&lt;/span&gt;
        &lt;input type="hidden" class="num_questions" name="numQuestion" value="1"&gt;
    &lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td rowspan="3"&gt;Question:&lt;/td&gt; 
    &lt;td rowspan="3"&gt;
        &lt;textarea class="questionTextArea" id="mainTextarea" rows="5" cols="40" name="questionText"&gt;&lt;/textarea&gt;
    &lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
</code></pre>

<p>UPDATE:</p>

<p>I have included links to both applications. One that works but does not include $qid, and one that includes $qid and doesn't work but which I do need working. Please follow steps in both applications so you can test it yourself and see what is happening:</p>

<p><a href="http://helios.hud.ac.uk/u0867587/Mobile_app/QandATable2.php" rel="nofollow">Application 1</a>: No $qid but working.</p>

<p><a href="http://helios.hud.ac.uk/u0867587/Mobile_app/QandATable3.php" rel="nofollow">Aplication 2</a>: Contains $qid but not working:</p>

<p>Follow steps below for both applications:</p>

<ol>
<li>Click on "Add Question" button, then will add a textarea within a new row.</li>
<li>Click on the "Green Plus" button within the table row you just added, a modal window will appear.</li>
<li>In modal window it displays a search bar, in search bar type in "AAA" and click on "Search" button</li>
<li>Results will appear of your search, click on "Add" button to add a row. You will find out modal window is closed but the content from the "Question" field is not added in the textarea within the row you clicked on the green plus button</li>
</ol>
