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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:32:10+00:00 2026-06-12T01:32:10+00:00

I have a web app (PHP) and I have to make this change. I

  • 0

I have a web app (PHP) and I have to make this change. I am more of a database, scripting guy, please bear with me on this one!

I have 8 check boxes (think numbered 1~8) in a form. I have to implement a condition where in :

If one of the first 4 checkboxes are checked (only one checkbox can be checked in the first 4),
Then the next 4 checkboxes should be disabled
Else the next 4 checkboxes should be enabled.

My solution :

  • Make the first 4 checkboxes radiobuttons to confirm to the only one
    checkbox can be selected
    condition.
  • Disable/Enable the next 4 checkboxes based on the above action. So,
    if the radiobutton is not selected, then the next 4 checkboxes should
    be available for selection.

I have to actually disable the checkboxes rather than hide using jQuery, so the checkboxes should be solidgray (uncheckable) when disabled.

Sample code (stripped off some formatting mess for others looking for a similar solution) :

        <div>
            <input type="checkbox" name="check1" value="1" id="check1" <?php if (!empty($rows['check1'])) { echo 'checked="checked"'; } ?> />
            <input type="checkbox" name="check2" value="1" id="check2" <?php if (!empty($rows['check2'])) { echo 'checked="checked"'; } ?> />
            <input type="checkbox" name="check3" value="1" id="check3" <?php if (!empty($rows['check3'])) { echo 'checked="checked"'; } ?> />
            <input type="checkbox" name="check4" value="1" id="check4" <?php if (!empty($rows['check4'])) { echo 'checked="checked"'; } ?> />
            <input type="checkbox" name="check5" value="1" id="check5" <?php if (!empty($rows['check5'])) { echo 'checked="checked"'; } ?> />
            <input type="checkbox" name="check6" value="1" id="check6" <?php if (!empty($rows['check6'])) { echo 'checked="checked"'; } ?> />
            <input type="checkbox" name="check7" value="1" id="check7" <?php if (!empty($rows['check7'])) { echo 'checked="checked"'; } ?> />
            <input type="checkbox" name="check8" value="1" id="check8" <?php if (!empty($rows['check8'])) { echo 'checked="checked"'; } ?> />
        </div>

My requests :

  • What is the most efficient way of doing this? (simple without complicating the problem)
  • Any sample code is greatly appreciated.
  • 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-12T01:32:11+00:00Added an answer on June 12, 2026 at 1:32 am

    I think this is what you’re looking for. You can achieve it using .index() to get current clicked checkbox. .slice() is used to get all elements at index 4 and after.

    $('input[type=checkbox]').change(function(){
        var $linputs =  $('input[type=checkbox]').slice(4);
        var $this = $(this);    
        $linputs.prop('disabled',($this.index() < 4 && this.checked));        
        if($this.index() < 4 && this.checked){
            $linputs.prop('checked',false);
        }
    });​
    

    FIDDDLE

    Or is it something like this that you want? Where only one of the first four checkboxes can be checked. If one is checked then all the others will be disabled.

    $('input[type=checkbox]').change(function(){
        var $this = $(this);    
        $(linputs).prop('disabled',($this.index() < 4 && this.checked));        
        if($this.index() < 4 && this.checked){
            $(linputs).prop('checked',false);
        }
    });​
    

    http://jsfiddle.net/h5wDr/

    EDIT:

    if you have other checkboxes in the page and want to be able to separate them from this logic, you can add context in the selector so it keeps this code isolated to only those within this div like so

    <div id='test'>
                    <input type="checkbox" name="check1" value="1" id="check1" >first
                <input type="checkbox" name="check2" value="1" id="check2" >second
                <input type="checkbox" name="check3" value="1" id="check3" >third
                <input type="checkbox" name="check4" value="1" id="check4" >fourth
                <input type="checkbox" name="check5" value="1" id="check5" >fifth
                <input type="checkbox" name="check6" value="1" id="check6" >sixth
                <input type="checkbox" name="check7" value="1" id="check7" >seventh
                <input type="checkbox" name="check8" value="1" id="check8" >eight
    </div>
    

    Then just add the context

    var $inputs = $('input[type=checkbox]', $('#test')); 
    // this will only select checkboxes within the element with id=test
    

    http://jsfiddle.net/h5wDr/2/

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

Sidebar

Related Questions

So I have this php web app, and one of my folder contains some
I have to update one web app from Java to PHP and I found
I have a PHP app running happily on the following system: web app: PHP
OK, I have a web app that uses PHP, MySQL and JavaScript. In an
I'm writing a simple web app in PHP that needs to have write access
I'm working on a class-based php web app. I have some places where objects
I have a php web service that takes the request from android/iphone app and
I have an iOS app sending requests to a PHP based web service ,
I have a web-app with a Java back-end that uses Tomcat jdbc-pool for database
I am going to make a simple web app. It will only have a

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.