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 :

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

And use it in your validation function

function validation(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++;
      return false;
    }
  });
  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 variable
  if (msg.length > 0) {
    alert("You have errors on Question Number: " + qNumber + "\n\n" + msg.join("\n"));
    return false;
  } else {
    return true;
  }
}

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