Reputation: 175
I have a checkboxlist. which has three items
if someone selected Unknown then it should disable the other selection on the checkboxlist. if Unknown is selected then nothing can be selected. Any j query, java-script, c# code helps please...
Upvotes: 3
Views: 1441
Reputation: 2207
Here, try this: http://jsfiddle.net/m8Leu/
// store the inputs and bind the change event
var $inputs = $( ".chkGroup input" );
$inputs.on( "change" , function(e) {
// store the item that changed and the ones that didnt.
var $changed = $(e.target);
var $others = $inputs.not( $changed );
// if the item that changed is "unknown"
if( $changed.hasClass( "unique" ) ) {
// save the state of the "unknown" chk
// and set the other chks to it's state
var state = $changed.prop( "checked" )
$others.prop( "disabled", state );
// for good measure, we'll uncheck the
// others because they are disabled
if( state ) {
$others.prop( "checked" , false );
}
}
});
Upvotes: 0
Reputation: 6544
You can use below code in jquery to handle this.
$(document).ready(function(){
$("#unknown").change(function(){
if($(this).is(":checked"))
$("#male, #female").attr('disabled','disabled');
else
$("#male, #female").removeAttr('disabled','disabled');
});
});
Here's the demo http://jsfiddle.net/nKdJg/3/
Upvotes: 1
Reputation: 172378
You can try something like this:-
$('.optionBox input:checkbox').click(function(){
var $x= $('.optionBox input:checkbox');
if($(this).is(':checked')){
$x.not(this).prop('disabled',true);
}
else
{
.....
}
})
Upvotes: 1