views:

226

answers:

2

Hello All,

Here is jquery code which hides my table cells with the ID of .style2:

 $('#myRadioButtonList').change(function() {

    if ($(this).attr('checked') == true && $(this).val() == "HB") {
        $('.style2').hide("slow");
    };
   });

and here is my radiobuttonlist

     <asp:RadioButtonList ID="myRadioButtonList" runat="server">
         <asp:ListItem Selected="True" Value="HB">None</asp:ListItem>
         <asp:ListItem Value="HOBSKS">Service </asp:ListItem>
         <asp:ListItem Value="OBAKS">Open Service</asp:ListItem>
         <asp:ListItem Value="BBKS">Close Service</asp:ListItem>
     </asp:RadioButtonList>

I am inspired by this topic

http://stackoverflow.com/questions/1159567/using-jquery-with-radiobuttons-to-hide-show-table-rows

This way my jquery is not working, there are mistakes in the part

if ($(this).attr('checked') == true && $(this).val() == "HB") 

I tried those two conditions above alone, and they both are not working. I need to reach to my radiobuttons but seems like I can't. Then how should I write that part in order to make my code work.

Thanks.

A: 

Could be that you're using the single "&", try "&&" for the boolean operator

if ($(this).attr('checked') == true && $(this).val() == "HB") 
David Archer
The two conditions within if statement are both not working when they are alone, like if ($(this).val() == "HB") is also not working, If I remove the if, then it hides the cells.
stckvrflw
+1  A: 
if ( ($(this).attr('checked') == true) && ($(this).val() == "HB") )

The boolean operator is probably what did it, as David said so well, but it's also good to put ()s around any phrases that might trip up your brain or the browser.

update Oh, your $(this) is pointing to the list, and not to the list items. Try changing your selector to match your HTML output for the items that will change.

update 2 Looks like you need to change your initial selector. Right now you're listening for a change in the table/list overall--you want to listen for a change in all of the radio buttons in the list. So try $("#myRadioButtonList input[type=radio]") instead.

D_N
No the fact that the two conditions within if statement are both not working when they are alone too.
stckvrflw
@stckvrflw Updated. I don't know the HTML output you have, so that's as specific as I can be.
D_N
"Try changing your selector to match your HTML output for the items that will change." Actually that is the part that I couldn't do, What do you mean by html output, my html output is the default output generated by asp.net, with the radiobuttonlist code above.
stckvrflw
D_N
@stckvrflw See my second update, actually, before going through all that. Best of luck!
D_N
Ok I am updating my question, btw I will ask something not to you specially but in general. If a question drops too low in the main page of stackoverflow, that really kills the question and you don't get any view or any more answers, and even updating is not working to make the question come back to live, I won't use a bounty since I know that not much people saw the question yet, I mean it is not such an hard question to use bounty on, then what should someone do ?
stckvrflw
Updating the question proper usually bounces it back to the top.
D_N
I didn't knew that. Thanks. Now I will look for your second update.
stckvrflw
Thanks, it works (:
stckvrflw
Sweet! Glad it did.
D_N