Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to disable textarea after all the rows have been added
    primarykey
    data
    text
    <p>I have a table where the user can add rows to it but each row is numbered. Now the user enters a number in a textbox for the number of rows he/she wants to add before they actually start adding rows. Below is the code where if the number of rows that has been added is over the number entered by the user, then it stops adding the rows.</p> <pre><code>if (qnum &gt; &lt;?php echo (int)@$_POST['textQuestion']; ?&gt;) { return; } </code></pre> <p>Example: if user entered in the number 5 in a textbox, then the user can only add 5 rows, if the user tries to add another row, then no row is added because user can't add more than 5 rows.</p> <p>Now the above works fine. But then what I want to do is that when the number of rows added has met its limit, then I want it to disable the textarea on top so i changed the code to this below:</p> <pre><code> if (qnum &gt; &lt;?php echo (int)@$_POST['textQuestion']; ?&gt;) { $('#questionTextArea').attr('disabled', 'disabled'); return; } </code></pre> <p>The problem is that if I do the code above then it disables the textarea straight away which is incorrect. What should happen is that it should allow the user to add the maximum table rows it is allowed to add and when the user reaches that limt, then disable the textarea. Does anyone know how to achieve this?</p> <p>Below is the function where it adds table rows:</p> <pre><code>function insertQuestion(form) { if (qnum &gt; &lt;?php echo (int)@$_POST['textQuestion']; ?&gt;) { $('#questionTextArea').attr('disabled', 'disabled'); return; } var $tbody = $('#qandatbl &gt; tbody'); var $tr = $("&lt;tr class='optionAndAnswer' align='center'&gt;&lt;/tr&gt;"); var $qid = $("&lt;td class='qid'&gt;" + qnum + "&lt;/td&gt;"); $tr.append($qid); $tbody.append($tr); $(form).find('.numberOfQuestions').val(qnum); ++qnum; } </code></pre> <p>Below is the textarea I want to disable:</p> <pre><code>&lt;table id="question"&gt; &lt;tr&gt; &lt;td rowspan="3"&gt;Question:&lt;/td&gt; &lt;td rowspan="3"&gt; &lt;textarea id="questionTextArea" rows="5" cols="40" name="questionText"&gt;&lt;/textarea&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload