Jump to content
Larry Ullman's Book Forums

When checkbox is checked, disable other checkboxes


Recommended Posts

When checkbox is checked, disable other checkboxes 

Question : 1.When one particular value checkbox is checked out of many checkbox in 1st div then disable same value checkbox in 2nd and 3rd div  

                   2.When one particular value checkbox is checked out of many checkbox in 2nd div then disable same value checkbox in 1st and 3rd div  

                   3.When one particular value checkbox is checked out of many checkbox in 3rd div then disable same value checkbox in 1st and 3rd div  

How can we do this with javascript or J query

Link to comment
Share on other sites

Disabling a checkbox in JS is actually really easy. You simply do the following:

checkboxDomElem.disabled = true;

And you can toggle the checkbox back on by setting disabled to false.

The trick is writing the correct logic in your JS (or PHP, and then pass it over to your JS) that knows that when you click a particular checkbox in the first row to disable three particular checkboxes in the second row, etc., etc.

For that, there are any number of things you can do, but I personally prefer Vue.js these days. It's an extremely powerful JS framework that makes this stuff easy. With it, you essentially just have to pass it a dependency tree, so that it knows which checkboxes are conditionally dependent on which others and you're done.

Good luck!

Link to comment
Share on other sites

Hi HartleySan,

Actually in three separate  div common 1 to 20 data retrieve from database so all three div have same 1 to 20 data . my moto in all three div same data so all row also same in three div . So if first row select in first div then same first row hidden of other two div . So user if select one data then user can't select same data in other two box . its help to restriction  to select same data in different different div

Link to comment
Share on other sites

The key to figuring this out is remember that if multiple radio buttons have the same name, only one can be checked. So just write your code to create the proper names based upon the restriction you want to put in place.

Link to comment
Share on other sites

 Share

×
×
  • Create New...