$( "[id*=CheckBoxList1] input:checkbox" ).change( function () { var maxSelection = 3; if ($( "[id*=CheckBoxList1] input:checkbox:checked" ).length > maxSelection) { $( this ).prop( "checked" , false ); alert( "Please select a maximum of " + maxSelection + " items." ); } }) |
Thursday, April 23, 2015
ASP.NET CheckBoxList Operations with jQuery - Max Selection Limit
ASP.NET CheckBoxList Operations with jQuery - Check Items By Text
//Check Items by Text var selText = [ 'Item-1' , 'Item-3' ]; var $ctrls = $( "[id*=CheckBoxList1]" ); for ( var i = 0; i < selText.length; i++) { $ctrls.find( 'label:contains("' + selText[i] + '")' ).prev().prop( 'checked' , true ); } |
ASP.NET CheckBoxList Operations with jQuery - Check Items By Value:
//Check Items by value var selValue = [1, 2, 4]; var $ctrls = $( "[id*=CheckBoxList1]" ); for ( var i = 0; i < selValue.length; i++) { $ctrls.find( 'input:checkbox[value=' + selValue[i] + ']' ).prop( 'checked' , true ); } |
ASP.NET CheckBoxList Operations with jQuery - Check Items By Index
//Check Items by index
var
selIndex = [0, 2, 3];
for
(
var
i = 0; i < selIndex.length; i++) {
$(
"[id*=CheckBoxList1] input:checkbox"
).eq(selIndex[i]).prop(
'checked'
,
true
);
}
Subscribe to:
Posts (Atom)