mercredi 7 octobre 2015

JavaScript checkbox checking related issue

After checking a checkbox, when I select another option it still remains checked. I want to uncheck it when I select another option, but it isn't doing so. The code is not working when I use bootstrap css. Where is the bug?

HTML :

<select class="form-control job-subcategory" autocomplete="off" name="job_subcategory">
    <option class="sub-catg-options" value="">Select Sub-Category(Optional)</option>
    <option class="electric-subcategory" value="Emergency Electricians">Emergency Electricians</option>
    <option class="electric-subcategory" value="Alarm Installer">Alarm Installer</option>
    <option class="electric-subcategory" value="Electrical Lighting">Electrical Lighting</option>
    <option class="electric-subcategory" value="Back Up Generators">Back Up Generators</option>
</select>

    <label class="residen-label">Type of services you require</label>

    <div class="btn-group" data-toggle="checkbox">
        <span class="button-checkbox">
            <button type="button" class="btn electric-appliances" data-color="primary">Wiring</button>
            <input type="checkbox" value="Wiring" name="ts-requires"  class="hidden" />
        </span>

        <span class="button-checkbox electric-ppoints">
            <button type="button" class="btn electric-appliances" data-color="primary">Powerpoints</button>
            <input type="checkbox" value="Powerpoints" name="ts-requires" class="hidden" />
        </span>

        <span class="button-checkbox light-fittings">
            <button type="button" class="btn electric-appliances" data-color="primary"> light-fittings</button>
            <input type="checkbox" value="Lighting fittings" name="ts-requires" class="hidden" />
        </span>

        <span class="button-checkbox electric-appliance">
            <button type="button" class="btn electric-appliances" data-color="primary">Appliances</button>
            <input type="checkbox" value="Appliances" name="ts-requires" class="hidden" />
        </span>

        <span class="button-checkbox">
            <button type="button" class="btn electric-appliances" data-color="primary">Solar Power</button>
            <input type="checkbox" value=" Solar Power" name="ts-requires" class="hidden" />
        </span>

        <span class="button-checkbox">
            <button type="button" class="btn electric-appliances" data-color="primary"> Switchboards</button>
            <input type="checkbox" value="Switchboards" name="ts-requires" class="hidden" />
        </span>         

        <span class="button-checkbox">
            <button type="button" class="btn electric-appliances" data-color="primary">Other</button>
            <input type="checkbox" value="Srequire Other" name="ts-requires" class="hidden" />
        </span>                             

    </div>          

</div>

My JS code:

$('.job-subcategory').change(function () {
    if ($('.job-subcategory').val() == "Emergency Electricians") {
        $(':checkbox').prop('checked', false);
    }
    else if ($('.job-subcategory').val() == "Alarm Installer") {
        $(':checkbox').prop('checked', false); 
    }
    else if ($('.job-subcategory').val() == "Electrical Lighting") {
        $(':checkbox').prop('checked', false);     
    }
    else if ($('.job-subcategory').val() == "Back Up Generators") {
        $(':checkbox').prop('checked', false);     
    }

    $('.btn-group').find('button-checkbox').removeClass('active');

    });




Aucun commentaire:

Enregistrer un commentaire