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 8024885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:59:07+00:00 2026-06-04T22:59:07+00:00

Problem: To make a selection of radio buttons and compare a number from a

  • 0

Problem:

To make a selection of radio buttons and compare a number from a text field with a number in array. If true, then take no action, else switch div with another div.

The HTML code:

<!-- Step 1 - Choose level -->
<label class="control-label">Level:</label>
<label class="radio"><input type="radio" name="level" id="level" value="1">C-level</label> 
<label class="radio"><input type="radio" name="level" id="level" value="2">D-level</label>

<!-- Step 2 - This apply only if choice 1 (C-level) is chosen -->
<label class="control-label">Number of authors:</label>
<label class="radio"><input type="radio" name="authors" id="authors" value="1">1 author</label> 
<label class="radio"><input type="radio" name="authors" id="authors" value="2">2 authors</label>

<!-- Step 2 - This apply only if choice 2 (D-level) is chosen -->
<label class="control-label">Credits:</label>
<label class="radio"><input type="radio" name="credits" id="credits" value="1">15 credits</label> 
<label class="radio"><input type="radio" name="credits" id="credits" value="2">30 credits</label>

<!-- Step 3 - This apply for both choice 1 and 2 -->
<label class="control-label">Type of study:</label>
<label class="radio"><input type="radio" name="study" id="study" value="1">Within</label> 
<label class="radio"><input type="radio" name="study" id="study" value="2">Between</label>

<!-- Check the number in this input field against the criteria in $within or $between -->
<label class="control-label">Participants:</label>
<input class="input-small" id="participants" name="participants" type="text">

The jQuery code:

<script type="text/javascript">
    $(document).ready(function()
    {       
        var numbers = {
            '1': {  // whithin
                '1': {  // C
                    '1': 36,
                    '2': 63
                },
                '2': {  // D
                    '1': 54,
                    '2': 63
                }
            },
            '2': {  // between
                '1': { // C
                    '1': 60,
                    '2': 105
                },
                '2': { // D
                    '1': 90,
                    '2': 105
                }
                // ...
            }
        };

        $('#participants').change(function() 
        {
            var choice1 = $('input[name=level]:checked').val();

            if (choice1 == '1') 
            {
                var choice2 = $('input[name=authors]:checked').val();
            } 
            else 
            {
                var choice2 = $('input[name=credits]:checked').val();
            }

            var choice3 = $('input[name=study]:checked').val();
            var number = numbers[choice3][choice1][choice2];

            if ($(this).val() < number) 
            {
                $('#part').addClass('error');
            } 
            else 
            {
                $('#part').removeClass('error');
            }
        }
    });
</script>

Extended explanation:

The idea is to take the value of each selection and add them up to see if they correspond to the value given in one of the arrays.

Scenario:

  1. User selects “C-level” (value=1), then selects “2 authors” (value=2), equals 12 when concatenated.
  2. User selects “Between” (value=2) and types in the number 95 in text field (id/name=number).
  3. When user moves focus from text field, jQuery should compare.

Result:

jQuery goes into the array $between, looks up the value 12 and see it’s 105. 95 is less and not equal to 105, therefore DIV 1 should be replaced with DIV 2 (while keeping the value the user has typed in).

DIV Code:

<div id="part" class="control-group">
    <label class="control-label">Participants:</label>

    <div class="controls">
        <div class="input-prepend">
            <input class="input-small" id="participants" name="participants" type="text">
        </div>
    </div>
</div>

If user types in a different value and moves focus, recalculation should be done. If value in text field is equal to or above the value in the array, then do nothing.

Any help is appreciated and I wouldn’t have typed this if I wasn’t really stuck! Thanks in advance.

  • 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-04T22:59:09+00:00Added an answer on June 4, 2026 at 10:59 pm
    var numbers = {
        '1': {  // whithin
            '1': {  // C
                '1': 36,
                '2': 63
            },
            '2': {  // D
                '1': 54,
                '2': 63
            }
        },
        '2': {  // between
            // ...
        }
    };
    $('#number').change(function() {
        var choice1 = $('input[name=level]:checked').val();
        if (choice1 == '1') {
            var choice2 = $('input[name=authors]:checked').val();
        } else {
            var choice2 = $('input[name=credits]:checked').val();
        }
        var choice3 = $('input[name=study]:checked').val();
        var number = numbers[choice3][choice1][choice2];
        if ($(this).val() < number) {
            $('#yourDiv').addClass('error');
        } else {
            $('#yourDiv').removeClass('error');
        }
    });
    

    I would suggest to use strings instead of 1/2 – it is easier to understand and less error-prone.

    If that PHP array is dynamic, you can set javascript array using function json_encode:

    <script>
        var numbers = <?php echo json_encode($numbers); ?>;
        // rest of code
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I make selection in ComboBox, and then type some text in TextBox, I
From what I have gathered, in order to make a label of a radio
The problem: I make jQuery .ajax calls by clicking on some cursor images in
I have the following problem: I make the call to the method of a
I make the problem shorter. Actually I have data much longer than this. I
I'm having a problem trying to make eclipse and aspectj work for Dynamic Web
It's a well known problem that executing make test doesn't build the tests as
The Holy Grail of programming is to solve a problem once and make continual
The problem I am trying to make a generic http module in asp.net C#
I have following problem: I have to make a ASP.NET Webapplication with a two-row

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.