Skip to content Skip to sidebar Skip to footer

How To Display Correct Number In Alert

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

Solution 1:

I assume that, as you said, this code permits to retieve the question number :

echo$searchQuestionNo[array_search($questionId, $searchQuestionId)]

Add your question number as an attribute q_number in your input element :

<inputclass="individualMarks q<?phpecho$questionId?>_mark"q_number="<?phpecho$searchQuestionNo[array_search($questionId, $searchQuestionId)]; ?>"q_group="1"name="answerMarks[]"type="text"data-type="qmark"data-qnum="<?phpecho$questionId?>"onkeypress="return isNumberKey(event)"maxlength="3"value="0" />

And use it in your validation function

functionvalidation(group) {
  var msg = [];

  var qNumber = null;

  var nb = 0; // Number of blank values
  $("input[data-qnum='" + group + "']").each(function () {

    //Assign the question number
    qNumber = $(this).attr('q_number');

    if ($(this).val() == '') {
      nb++;
      returnfalse;
    }
  });
  if (nb != 0) {
    msg.push("\u2022 You have not entered in a value in all the Penalty Marks textbox \n");
  }

  //Use qNumber instead of the group variableif (msg.length > 0) {
    alert("You have errors on Question Number: " + qNumber + "\n\n" + msg.join("\n"));
    returnfalse;
  } else {
    returntrue;
  }
}

Post a Comment for "How To Display Correct Number In Alert"