Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9142429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:46:53+00:00 2026-06-17T09:46:53+00:00

I am having issue with a question number displayed in an alert. Instead of

  • 0

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:

You have errors on question number: 115

When it should say You have errors on question number: 3 for example

Now this code display question id: value="<?php echo$questionId?>"

This code display question number: echo$searchQuestionNo[array_search($questionId, $searchQuestionId)]

But when I tried to do this:

<input type='hidden' id='num_groups' name='num_groups' value='<?php echo$searchQuestionNo[array_search($questionId, $searchQuestionId)]`?>'>

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:

<input type='hidden' id='num_groups' name='num_groups' value='<?php echo$questionId?>'>

Then it displays the questionId in the alert and the alert actually works.

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?

Below is main code so you can see where everything comes from:

PHP:

    <?

       // 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->bind_result($dbSessionId, $dbSessionName, $dbQuestionId, $dbQuestionNo, $dbQuestionContent, $dbAnswer, $dbAnswerId, $dbQuestionMarks, $dbOptionId, $dbOptionType);


        $searchQuestionId[] = $dbQuestionId;
        $searchQuestionNo[] = $dbQuestionNo;
      } 

?>



</head>

<body>


<form id="PenaltyMarks" action="<?php echo htmlentities($action); ?>" method="post">


<?php

$ques_ans = array();    //to store incorrect answers against ques no.

$q_occ_count = array_count_values($searchQuestionId);
foreach($searchQuestionId as $key => $questionId)
{
.....
}


?>
<table id='penaltytbl'>
<thead>
<tr>
<th class='questionth'>Question No.</th>
<th class='questionth'>Question</th>
</tr>
</thead>
<tbody>
<?php

foreach($ques_ans as $questionId => $inc_ans)
{


?>

<tr class="questiontd">

<td class="questionnumtd q<?php echo$searchQuestionNo[array_search($questionId, $searchQuestionId)]?>_qnum" rowspan="<?php echo$q_row_span?>"><?php echo$searchQuestionNo[array_search($questionId, $searchQuestionId)]?>
<input type="hidden" name="numQuestion" value="<?php echo$questionId?>" />
    </td>


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

</tr>
<?php
}

?>
</tbody>
</table>

<p>
<input type='hidden' id='num_groups' name='num_groups' value='<?php echo$questionId?>'>
<input id="submitBtn" name="submitPenalty" type="submit" value="Submit Marks" />
</p>

</form>

Jquery:

  < script type = "text/javascript" >


    myClickHandler = function (e) {
      var ng = $('#num_groups').val();
      for (var group = 1; group 
           <= 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 >
          0) {
        alert("You have errors on Question Number: " + group + "\n\n" + msg.join("\n"));
        return false;
      } else {
        return true;
      }
    }




    < /script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:46:54+00:00Added an answer on June 17, 2026 at 9:46 am

    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;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Excuse the simple question, the issue i'm having maybe due to lack of sleep.
I've just posted a question on stackoverflow about a hide/show issue I was having
Hi guys I am having issue I have this query: SELECT * FROM useraccount
Just started mongo and started having issue with querying already. i have a collection
Original Question: I've been having a major headache over what should be an extremely
I'm having a strange issue with my form in CakePHP. I have a series
(This question is indirectly related to a programming issue I'm having; if you think
I have read a number of questions on this site about this issue, I
I'm having an issue trying to fix a conflict between both libraries and have
Im having an issue with my progress bar. Now I have looked through all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.