tags:

views:

48

answers:

2

Hi,

I need to access radiobutton groupname in my jquery. However, groupname that's rendered for an asp radiobutton is kind of different. Example:

<asp:RadioButton runat="server" GroupName="payment" ID="creditcard" Checked="true" value="creditcard" />

will generate:

<input type="radio" checked="checked" value="creditcard" name="ctl00$ContentPlaceHolder1$payment" id="ctl00_ContentPlaceHolder1_creditcard">

I can't work with <%=creditcard.GroupName%> in jquery. Is there a way I can get the generated groupname or name for it?

A: 

This will get you the proper group name

$("#<%=creditccard.ClientID %>").attr("name");
hunter
+1  A: 

You can do this:

$("input[name$=payment]")

This uses the $= ends with selector, finding names that end with payment, as long as you don't have multiple of these across containers, it'll work.

Alternatively, to be based on this specific control:

$("input[name=<%=creditccard.GroupName %>]")
Nick Craver
thanks. the second option doesn't work because the generated name is not the groupname anymore for the element.btw, do you know why the following doesn't work?var paymentGroupName = $("#<%=creditcard.ClientID%>").attr("name");$("input[name='" + paymentGroupName +"']")
@rap-uvic - Are you calling it before document.ready?
Nick Craver
nope it's within it. i'll paste code above.
@rap-uvic - That code works fine here, someone else outside that is interfering.
Nick Craver
yes you're right it does work! I was just messing up somewhere. thanks for your help. Although I think I should mark Hunter's answer as the answer. I hope that's ok with you. sorry.