In my table, users can add rows with each row being numbered. Before adding any rows, the user must enter a number in a textbox indicating how many rows they want to add. Once that number is reached, no more rows can be added.
if (qnum >= <?php echo (int)@$_POST['textQuestion']; ?>) {
return;
}
For example, if a user enters '5' in the textbox, only 5 rows can be added. Any attempts to add more will be blocked as the limit has been reached.
My question is, once the user reaches the maximum number of rows, I want to disable a textarea (making it unclickable and changing its color to show it's disabled). I also want to disable a hyperlink so it cannot be clicked on (again changing its color to indicate it's inactive). Does anyone know how to achieve this?
Below is the code for the hyperlink and the textarea:
<table id="question">
<tr>
<th colspan="2">
Question Number <span id="questionNum">1</span>
</th>
</tr>
<tr>
<td rowspan="3">Question:</td>
<td rowspan="3">
<textarea id="questionTextArea" rows="5" cols="40" name="questionText"></textarea>
<span href="#" class="link">[Question link]</span>
</td>
</tr>
</table>
Jquery function showing how a table row is added:
function insertQuestion(form) {
var questionarea=(form.questionText.length)
? form.questionText[0]
: form.questionText;
var context = $('#optionAndAnswer');
var currenttotal = context.find('.answerBtnsOn').length;
alertErrors = "";
if (questionarea.value == ""){
if (qnum >= <?php echo (int)@$_POST['textQuestion']; ?>) {
return;
}
var $tbody = $('#qandatbl > tbody');
var $tr = $("<tr class='optionAndAnswer' align='center'></tr>");
var $qid = $("<td class='qid'>" + qnum + "</td>");
$tr.append($qid);
$tbody.append($tr);
}
Html table where the new row is added:
<table id="qandatbl" align="center>
<thead>
<tr>
<th class="qid">Question No</th>
</tr>
</thead>
<tbody></tbody>
</table>
View this demonstration here. You can write a question in the top textarea, then click the button to add it as a new row. My goal is to disable the top textarea once the row limit is reached.