Jquery - checkbox selection by name in asp.net

html pushed to the page:


<span class="AuthorizationGroup"><input id="ctl00_ContentPlaceHolder1_hsLkup_chkAuthApproved" type="checkbox" name="ctl00$ContentPlaceHolder1$hsLkup$chkAuthApproved" /></span> Approved&nbsp;&nbsp;

<span class="AuthorizationGroup"><input id="ctl00_ContentPlaceHolder1_hsLkup_chkAuthDeclined" type="checkbox" name="ctl00$ContentPlaceHolder1$hsLkup$chkAuthDeclined" /></span> Declined&nbsp;&nbsp;

<span class="AuthorizationGroup"><input id="ctl00_ContentPlaceHolder1_hsLkup_chkAuthNoResponse" type="checkbox" name="ctl00$ContentPlaceHolder1$hsLkup$chkAuthNoResponse" checked="checked" /></span> No Response 



I can get my checboxes without any problem like this:


$([COLOR=maroon]".[/COLOR]AuthorizationGroup[COLOR=maroon]"[/COLOR]).find([COLOR=maroon]"input[type='checkbox']"[/COLOR]).checkboxUncheckOthers([COLOR=blue]true[/COLOR], [COLOR=blue]false[/COLOR]); 

When in the uncheck plugin in, i use “name”, i get object doesn’t support this property or method. Basically, if current CLICKED one is checked then i want to uncheck all the remaining that are checked in that group. This code works with html check boxes. I think, the problem is the $ in the name (pushed by asp.net). How can i get around this problem?

plugin code


[COLOR=darkgreen]//checkbox uncheck others[/COLOR] jQuery.fn.checkboxUncheckOthers = [COLOR=blue]function[/COLOR] (blnKeepCurrentChecked, blnApplyHighLight) {     
[COLOR=blue]if[/COLOR] (blnKeepCurrentChecked == [COLOR=blue]null[/COLOR] || blnKeepCurrentChecked == [COLOR=maroon]'undefined'[/COLOR] || [COLOR=blue]typeof[/COLOR] blnKeepCurrentChecked != [COLOR=maroon]'boolean'[/COLOR])         
blnKeepCurrentChecked = [COLOR=blue]false[/COLOR];     [COLOR=blue]
if[/COLOR] (blnApplyHighLight == [COLOR=blue]null[/COLOR] || blnApplyHighLight == [COLOR=maroon]'undefined'[/COLOR] || [COLOR=blue]typeof[/COLOR] blnApplyHighLight != [COLOR=maroon]'boolean'[/COLOR])         
blnApplyHighLight = [COLOR=blue]false[/COLOR];       [COLOR=blue]
var[/COLOR] handleState = {         
item: [COLOR=blue]function[/COLOR] ($clicked, $obj) {             [COLOR=blue]
var[/COLOR] clickedIndex = $clicked.getIndexOfItemClickedRadioCheckBox();             $obj.each([COLOR=blue]function[/COLOR] (index) {                 
[COLOR=blue]if[/COLOR] (clickedIndex != index)                    
 $([COLOR=blue]this[/COLOR]).attr([COLOR=maroon]"checked"[/COLOR], [COLOR=blue]false[/COLOR]);                 [COLOR=blue]
else[/COLOR] [COLOR=blue]if[/COLOR] (clickedIndex == index && blnKeepCurrentChecked && !$([COLOR=blue]this[/COLOR]).is([COLOR=maroon]":checked"[/COLOR])) {                     
$([COLOR=blue]this[/COLOR]).attr([COLOR=maroon]"checked"[/COLOR], [COLOR=blue]true[/COLOR]);                                      
}             
});          
}       
};     [COLOR=blue]
return[/COLOR] [COLOR=blue]this[/COLOR].each([COLOR=blue]function[/COLOR] () {         
$([COLOR=blue]this[/COLOR]).click([COLOR=blue]function[/COLOR] () {             
alert($([COLOR=blue]this[/COLOR]).attr([COLOR=maroon]"name"[/COLOR]));             
handleState.item($([COLOR=blue]this[/COLOR]), $([COLOR=maroon]'input[name='[/COLOR] + $([COLOR=blue]this[/COLOR]).attr([COLOR=maroon]"name"[/COLOR]) + [COLOR=maroon]']'[/COLOR]));         });         $([COLOR=blue]this[/COLOR]).keyup([COLOR=blue]function[/COLOR] () {             handleState.item($([COLOR=blue]this[/COLOR]), $([COLOR=maroon]'input[name='[/COLOR] + $([COLOR=blue]this[/COLOR]).attr([COLOR=maroon]"name"[/COLOR]) + [COLOR=maroon]']'[/COLOR]));         });     }); }

I think you just need some quotes around your name selector:


handleState.item($(this), $('input[name="' + $(this).attr("name") + '"]')); 

The $ is a reserved character, but the selector is smart enough to handle those characters if the are inside the " quotes ".

Thanks, i’ll test this out tomorrow morning.

Made the changes and i am still getting the same error.

Little confused now, i used getElementById and then tried to check the check box, i got into object error.

I need to do little bit more research into this issue…

Run your code through something like: JSHint, A JavaScript Code Quality Tool. I think there might be some syntax issues with the code, or it could just be the way it was copied into the forums. Either way, doesn’t hurt to validate it.