Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to display correct number in alert
    primarykey
    data
    text
    <p>I am having issue with a question number displayed in an alert. Instead of displaying the question number, it is displaying the question id as the question number. So in the alert validation it states for example:</p> <pre><code>You have errors on question number: 115 </code></pre> <p>When it should say <code>You have errors on question number: 3</code> for example</p> <p>Now this code display question id: <code>value="&lt;?php echo$questionId?&gt;"</code></p> <p>This code display question number: <code>echo$searchQuestionNo[array_search($questionId, $searchQuestionId)]</code></p> <p>But when I tried to do this: </p> <pre><code>&lt;input type='hidden' id='num_groups' name='num_groups' value='&lt;?php echo$searchQuestionNo[array_search($questionId, $searchQuestionId)]`?&gt;'&gt; </code></pre> <p>It does not display question number for jquery alert. To be honest what happens is that the validation doesn't work as it doesn't appear. Yet if I kept the above code to what it was which value was the question id:</p> <pre><code>&lt;input type='hidden' id='num_groups' name='num_groups' value='&lt;?php echo$questionId?&gt;'&gt; </code></pre> <p>Then it displays the questionId in the alert and the alert actually works.</p> <p>So my question is how do I include the question number value in the alert yet be able to get the validation to work as well, like it does for questionid?</p> <p>Below is main code so you can see where everything comes from:</p> <p><strong>PHP:</strong></p> <pre><code> &lt;? // This will hold the search results $searchQuestionId = array(); $searchQuestionNo = array(); // Fetch the results into an array // get result and assign variables (prefix with db) $stmt-&gt;bind_result($dbSessionId, $dbSessionName, $dbQuestionId, $dbQuestionNo, $dbQuestionContent, $dbAnswer, $dbAnswerId, $dbQuestionMarks, $dbOptionId, $dbOptionType); $searchQuestionId[] = $dbQuestionId; $searchQuestionNo[] = $dbQuestionNo; } ?&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="PenaltyMarks" action="&lt;?php echo htmlentities($action); ?&gt;" method="post"&gt; &lt;?php $ques_ans = array(); //to store incorrect answers against ques no. $q_occ_count = array_count_values($searchQuestionId); foreach($searchQuestionId as $key =&gt; $questionId) { ..... } ?&gt; &lt;table id='penaltytbl'&gt; &lt;thead&gt; &lt;tr&gt; &lt;th class='questionth'&gt;Question No.&lt;/th&gt; &lt;th class='questionth'&gt;Question&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;?php foreach($ques_ans as $questionId =&gt; $inc_ans) { ?&gt; &lt;tr class="questiontd"&gt; &lt;td class="questionnumtd q&lt;?php echo$searchQuestionNo[array_search($questionId, $searchQuestionId)]?&gt;_qnum" rowspan="&lt;?php echo$q_row_span?&gt;"&gt;&lt;?php echo$searchQuestionNo[array_search($questionId, $searchQuestionId)]?&gt; &lt;input type="hidden" name="numQuestion" value="&lt;?php echo$questionId?&gt;" /&gt; &lt;/td&gt; &lt;td class="answermarkstd"&gt; &lt;input class="individualMarks q&lt;?php echo$questionId?&gt;_mark" q_group="1" name="answerMarks[]" type="text" data-type="qmark" data-qnum="&lt;?php echo$questionId?&gt;" onkeypress="return isNumberKey(event)" maxlength="3" value="0" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p&gt; &lt;input type='hidden' id='num_groups' name='num_groups' value='&lt;?php echo$questionId?&gt;'&gt; &lt;input id="submitBtn" name="submitPenalty" type="submit" value="Submit Marks" /&gt; &lt;/p&gt; &lt;/form&gt; </code></pre> <p><strong>Jquery:</strong></p> <pre><code> &lt; script type = "text/javascript" &gt; myClickHandler = function (e) { var ng = $('#num_groups').val(); for (var group = 1; group &lt;= ng; group++) { if (!validation(group)) return false; } }); function validation(group) { var msg = []; var nb = 0; // Number of blank values $("input[data-qnum='" + group + "']").each(function () { if ($(this).val() == '') { nb++; return false; } }); if (nb != 0) { msg.push("\u2022 You have not entered in a value in all the Penalty Marks textbox \n"); } if (msg.length &gt; 0) { alert("You have errors on Question Number: " + group + "\n\n" + msg.join("\n")); return false; } else { return true; } } &lt; /script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    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