SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Learning... tahirjadoon's Avatar
    Join Date
    Jan 2003
    Posts
    775
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jquery - checkbox selection by name in asp.net

    html pushed to the page:
    Code:
    <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:
    Code:
    $(".AuthorizationGroup").find("input[type='checkbox']").checkboxUncheckOthers(true, false);
    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
    Code:
    //checkbox uncheck others jQuery.fn.checkboxUncheckOthers = function (blnKeepCurrentChecked, blnApplyHighLight) {     
    if (blnKeepCurrentChecked == null || blnKeepCurrentChecked == 'undefined' || typeof blnKeepCurrentChecked != 'boolean')         
    blnKeepCurrentChecked = false;     
    if (blnApplyHighLight == null || blnApplyHighLight == 'undefined' || typeof blnApplyHighLight != 'boolean')         
    blnApplyHighLight = false;       
    var handleState = {         
    item: function ($clicked, $obj) {             
    var clickedIndex = $clicked.getIndexOfItemClickedRadioCheckBox();             $obj.each(function (index) {                 
    if (clickedIndex != index)                    
     $(this).attr("checked", false);                 
    else if (clickedIndex == index && blnKeepCurrentChecked && !$(this).is(":checked")) {                     
    $(this).attr("checked", true);                                      
    }             
    });          
    }       
    };     
    return this.each(function () {         
    $(this).click(function () {             
    alert($(this).attr("name"));             
    handleState.item($(this), $('input[name=' + $(this).attr("name") + ']'));         });         $(this).keyup(function () {             handleState.item($(this), $('input[name=' + $(this).attr("name") + ']'));         });     }); }
    The beauty of life is not dependent on how happy you are,
    but on how happy others can be because of you...

  2. #2
    SitePoint Enthusiast Anthony.Barnes's Avatar
    Join Date
    Aug 2011
    Location
    Canberra, Australia
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you just need some quotes around your name selector:

    Code JavaScript:
    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 ".

  3. #3
    Learning... tahirjadoon's Avatar
    Join Date
    Jan 2003
    Posts
    775
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, i'll test this out tomorrow morning.
    The beauty of life is not dependent on how happy you are,
    but on how happy others can be because of you...

  4. #4
    Learning... tahirjadoon's Avatar
    Join Date
    Jan 2003
    Posts
    775
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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...
    The beauty of life is not dependent on how happy you are,
    but on how happy others can be because of you...

  5. #5
    SitePoint Enthusiast Anthony.Barnes's Avatar
    Join Date
    Aug 2011
    Location
    Canberra, Australia
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •