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

  • SEARCH
  • Home
  • 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 7703661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:30:36+00:00 2026-05-31T23:30:36+00:00

i have a multiple amount of text fields, the amount of text fields is

  • 0

i have a multiple amount of text fields, the amount of text fields is due to how much data is in a database. The input for both are integers, all i want is when the values are inputted into the text fields it throws an error if the inputted data is larger than the value in the data base
for example
in a markscheme
the data inputted into the textbox is the mark given to the student and the data in the database is the maxmark for that particular question, so therefore it cannot exceed that value
so in effect i want to compare the values and if the text input value is larger than that of the one in the database it throws and error 🙂

  • 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-05-31T23:30:37+00:00Added an answer on May 31, 2026 at 11:30 pm

    If it’s OK for you to rely on your users having javascript enabled, I would say the easiest is to verify the data on the client side.

    You could do something like this:

    <html>
    <head>
      <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    </head>
    
    <body>
      <input type="text" value="5" name="grade[123]" data-max="10" />
    
      <script type="text/javascript">
        $(function() {
          $('input[type="text"]').blur(function(e) {
            var $this = $(this);
            var max = parseInt($this.data('max'), 10);
    
            if (parseInt($this.val(), 10) > max) {
              var name = $this.attr('name');
              console.error('Value ' + $this.val() + ' in field "' + name + '" exceed its maximum value of ' + max);
              $this.focus();
            }
          })
        });
      </script>
    </body>
    </html>
    

    Or you could replace all this logic with simple HTML5 number fields:

    <input type="number" value="5" name="grade[123]" min="0" max="10" />
    

    Obviously, one should never trust their users. You should always double-check the data on the server side and notify users about the possible errors.

    This is something you could do:

    <?php
    
    if (!empty($_POST)) {
        // ...
        // fetch max values from the database in the form of 
        // array(
        //     id => [max],
        // );
        $maxValues = array( /* ... */ );
    
        // prepare some error array if you want to show errors next to individual fields
        $errors = array();
    
        // ...and then loop through the posted array
        foreach ($_POST['grades'] as $id => $value) {
            // make sure the submitted value is an integer
            if (!ctype_digit($value) && !is_int($value)) {
                $errors[$id] = 'Invalid value';
                continue;
            }
    
            if ((int) $value > (int) $maxValues[$id]) {
                $errors[$id] = 'Value cannot be more than ' . $maxValues[$id];
            }
        }
    
        // assign errors to the view or do whatever is required in your script
        // ...
    }
    

    It shouldn’t be difficult to understand what I was doing there. Basically, have one reference array and the data array to verify against (note: your HMTL field names must have the square brackets in them to act as arrays). And then just loop through the submitted data and verify against the reference array.

    Just like Ryan Kempt said, there are lots of ways you could do it and without a specific example of your data structure or how you want the errors/exceptions to be presented to the user, it’s quite difficult to write you an exact code.

    Nevertheless, have a look at our suggestions and start from there. And best of luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple lines of data all sharing the same Company id. Is there
We have multiple environments (development, test, Production, etc). Using Oracle 10g. All values are
I have multiple classes that all derive from a base class, now some of
I have multiple threads (C# application running on IIS) running that all need to
I have a page with multiple lists. Each list has a different amount of
I have a large amount of log data that I need to get some
I have some data (text files) that is formatted in the most uneven manner
All though we have multiple sites (like spoon) to get us help with browser
I have multiple selects: <select id=one> <option value=1>one</option> <option value=2>two</option> <option value=3>three</option> </select> <select
I have multiple projects in a couple of different workspaces. However, it seems like

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.