Select other checkboxes with a checkbox in code

Home Forums Quform WordPress Select other checkboxes with a checkbox in code

This topic is: resolved
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #20113
    jerkski
    Participant

    Hello, I have a group of checkboxes, but would like each checkbox to preselect a group of checkboxes. For example, when I check checkbox A, it would then automatically check checkboxes 1,2,3. If I check checkbox B, it will check checkboxes 4,5,6.

    Is this possible?

    #20114
    jerkski
    Participant

    I got the following to work for selecting all checkboxes in a checkbox group. Is there any way I can get it to also deselect the checkboxes as well. iphorm_2_36 is my primary checkbox, and

    <script>
    jQuery(document).ready(function ($) {
    jQuery(‘.iphorm_2_36’).click(function(){
    var value = jQuery(this).val();
    var $amp = jQuery(‘.iphorm_2_154’);
    $amp.each(function () {
    {
    jQuery(this).prop(‘checked’, true);
    }
    });
    jQuery.uniform.update();
    }).change();
    });
    </script>

    #20115
    jerkski
    Participant

    Well, here is my crack at it… It works, but I think my code is getting confused because it selects the correct group of checkboxes, but then checking or unchecking another box deselected that group. Any tips on how to simplify this?

    <script>
    jQuery(document).ready(function ($) {
    jQuery(‘.iphorm_2_36’).click(function(){
    var value1 = jQuery(this).val();
    var $amp1 = jQuery(‘.iphorm_2_154’);
    $amp1.each(function () {

    if(jQuery(‘.iphorm_2_36’).is(“:checked”)&& value1 == ‘1’) {
    jQuery(this).prop(‘checked’, true);
    } else {
    jQuery(this).prop(‘checked’, false);
    }
    });
    jQuery.uniform.update();
    }).change();
    });
    </script>

    <script>
    jQuery(document).ready(function ($) {
    jQuery(‘.iphorm_2_36’).click(function(){
    var value2 = jQuery(this).val();
    var $amp2 = jQuery(‘.iphorm_2_153’);
    $amp2.each(function () {

    if(jQuery(‘.iphorm_2_36’).is(“:checked”)&& value2 == ‘2’) {
    jQuery(this).prop(‘checked’, true);
    } else {
    jQuery(this).prop(‘checked’, false);
    }
    });
    jQuery.uniform.update();
    }).change();
    });
    </script>

    <script>
    jQuery(document).ready(function ($) {
    jQuery(‘.iphorm_2_36’).click(function(){
    var value3 = jQuery(this).val();
    var $amp3 = jQuery(‘.iphorm_2_155’);
    $amp3.each(function () {

    if(jQuery(‘.iphorm_2_36’).is(“:checked”)&& value3 == ‘3’) {
    jQuery(this).prop(‘checked’, true);
    } else {
    jQuery(this).prop(‘checked’, false);
    }
    });
    jQuery.uniform.update();
    }).change();
    });
    </script>

    <script>
    jQuery(document).ready(function ($) {
    jQuery(‘.iphorm_2_36’).click(function(){
    var value4 = jQuery(this).val();
    var $amp4 = jQuery(‘.iphorm_2_156’);
    $amp4.each(function () {

    if(jQuery(‘.iphorm_2_36’).is(“:checked”)&& value4 == ‘4’) {
    jQuery(this).prop(‘checked’, true);
    } else {
    jQuery(this).prop(‘checked’, false);
    }
    });
    jQuery.uniform.update();
    }).change();
    });
    </script>

    <script>
    jQuery(document).ready(function ($) {
    jQuery(‘.iphorm_2_36’).click(function(){
    var value5 = jQuery(this).val();
    var $amp5 = jQuery(‘.iphorm_2_157’);
    $amp5.each(function () {

    if(jQuery(‘.iphorm_2_36’).is(“:checked”)&& value5 == ‘5’) {
    jQuery(this).prop(‘checked’, true);
    } else {
    jQuery(this).prop(‘checked’, false);
    }
    });
    jQuery.uniform.update();
    }).change();
    });
    </script>

    <script>
    jQuery(document).ready(function ($) {
    jQuery(‘.iphorm_2_36’).click(function(){
    var value6 = jQuery(this).val();
    var $amp6 = jQuery(‘.iphorm_2_158’);
    $amp6.each(function () {

    if(jQuery(‘.iphorm_2_36’).is(“:checked”)&& value6 == ‘6’) {
    jQuery(this).prop(‘checked’, true);
    } else {
    jQuery(this).prop(‘checked’, false);
    }
    });
    jQuery.uniform.update();
    }).change();
    });
    </script>

    <script>
    jQuery(document).ready(function ($) {
    jQuery(‘.iphorm_2_36’).click(function(){
    var value7 = jQuery(this).val();
    var $amp7 = jQuery(‘.iphorm_2_159’);
    $amp7.each(function () {

    if(jQuery(‘.iphorm_2_36’).is(“:checked”)&& value7 == ‘7’) {
    jQuery(this).prop(‘checked’, true);
    } else {
    jQuery(this).prop(‘checked’, false);
    }
    });
    jQuery.uniform.update();
    }).change();
    });
    </script>

    <script>
    jQuery(document).ready(function ($) {
    jQuery(‘.iphorm_2_36’).click(function(){
    var value8 = jQuery(this).val();
    var $amp8 = jQuery(‘.iphorm_2_160’);
    $amp8.each(function () {

    if(jQuery(‘.iphorm_2_36’).is(“:checked”)&& value8 == ‘8’) {
    jQuery(this).prop(‘checked’, true);
    } else {
    jQuery(this).prop(‘checked’, false);
    }
    });
    jQuery.uniform.update();
    }).change();
    });
    </script>

    <script>
    jQuery(document).ready(function ($) {
    jQuery(‘.iphorm_2_36’).click(function(){
    var value9 = jQuery(this).val();
    var $amp9 = jQuery(‘.iphorm_2_161’);
    $amp9.each(function () {

    if(jQuery(‘.iphorm_2_36’).is(“:checked”)&& value9 == ‘9’) {
    jQuery(this).prop(‘checked’, true);
    } else {
    jQuery(this).prop(‘checked’, false);
    }
    });
    jQuery.uniform.update();
    }).change();
    });
    </script>

    <script>
    jQuery(document).ready(function ($) {
    jQuery(‘.iphorm_2_36’).click(function(){
    var value10 = jQuery(this).val();
    var $amp10 = jQuery(‘.iphorm_2_162’);
    $amp10.each(function () {

    if(jQuery(‘.iphorm_2_36′).is(“:checked”)&& value10 == ’10’) {
    jQuery(this).prop(‘checked’, true);
    } else {
    jQuery(this).prop(‘checked’, false);
    }
    });
    jQuery.uniform.update();
    }).change();
    });
    </script>

    <script>
    jQuery(document).ready(function ($) {
    jQuery(‘.iphorm_2_36’).click(function(){
    var value11 = jQuery(this).val();
    var $amp11 = jQuery(‘.iphorm_2_163’);
    $amp11.each(function () {

    if(jQuery(‘.iphorm_2_36′).is(“:checked”)&& value11 == ’11’) {
    jQuery(this).prop(‘checked’, true);
    } else {
    jQuery(this).prop(‘checked’, false);
    }
    });
    jQuery.uniform.update();
    }).change();
    });
    </script>

    <script>
    jQuery(document).ready(function ($) {
    jQuery(‘.iphorm_2_36’).click(function(){
    var value12 = jQuery(this).val();
    var $amp12 = jQuery(‘.iphorm_2_164’);
    $amp12.each(function () {

    if(jQuery(‘.iphorm_2_36′).is(“:checked”)&& value12 == ’12’) {
    jQuery(this).prop(‘checked’, true);
    } else {
    jQuery(this).prop(‘checked’, false);
    }
    });
    jQuery.uniform.update();
    }).change();
    });
    </script>

    <script>
    jQuery(document).ready(function ($) {
    jQuery(‘.iphorm_2_36’).click(function(){
    var value13 = jQuery(this).val();
    var $amp13 = jQuery(‘.iphorm_2_165’);
    $amp13.each(function () {

    if(jQuery(‘.iphorm_2_36′).is(“:checked”)&& value13 == ’13’) {
    jQuery(this).prop(‘checked’, true);
    } else {
    jQuery(this).prop(‘checked’, false);
    }
    });
    jQuery.uniform.update();
    }).change();
    });
    </script>

    #20116
    jerkski
    Participant

    Found a better way!

    <script>
    jQuery(document).ready(function ($) {
    $(‘.iphorm_2_36’).click(function(){

    var $chkA = $(this),
    value1 = $chkA.val(),
    chkUnchk = $chkA.is(‘:checked’),
    ampX = ”;

    switch (value1) {
    case ‘1’:
    ampX = ‘.iphorm_2_154’;
    break;
    case ‘2’:
    ampX = ‘.iphorm_2_153’;
    break;
    case ‘3’:
    default:
    ampX = ‘.iphorm_2_155’;
    break;
    };
    $(ampX).each(function () {
    $(this).prop(‘checked’, chkUnchk);
    });

    jQuery.uniform.update();
    }).change();
    });
    </script>

    #20142
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy