How to check next checkbox

2

From the current selection of the checkbox, how to check the next checkbox element and disable all other checkboxes.

I have this code, which when marking a checkbox consequently all the others are disabled, but I need that when marking a checkbox automatically it marks the next checkbox and deactivates the others.

I tried the next () but I did not succeed

$(document).ready(function(){
$('#formNine input:checkbox').click(function(){

var $inputs = $('#formNine input:checkbox')

    if($(this).is(':checked')){
       $inputs.not(this).prop('disabled',true); // <-- disable all but checked one
    }else{
       $inputs.prop('disabled',false); // <--
    }

});

});

    
asked by anonymous 15.10.2014 / 20:04

1 answer

3

You can do with next() .

Adds at the end of if :

$(this).next().prop('checked', true).prop('disabled', false);

Looking like this:

if($(this).is(':checked')){
   $inputs.not(this).prop('disabled',true); // <-- disable all but checked one
   $(this).next().prop('checked', true).prop('disabled', false);
}else{
   $inputs.prop('disabled',false); // <--
}
    
15.10.2014 / 20:35