0

I have an ASP.NET Forms page and there is a fieldset and inside this there are items that each have a radio button. Basically I want to determine if a certain item is checked. However, it appears that it's location could move and therefore the id could change if the database is updated. How can I determine if the item is checked using if the id attribute can change? I don't think the value would change, how can I determine if it is checked by using the value attribute?

I would like to add a class as suggested but I really only want to use javascript and not change any of the ASP.NET code in the .aspx file.

<fieldset style="padding-left: 5px;">
  <input id="ctl00_ctl00_MainContent_ContentPlaceHolder_rblstRole_8" type="radio" name="ctl00$ctl00$MainContent$ContentPlaceHolder$rblstRole" value="36">
  <label for="ctl00_ctl00_MainContent_ContentPlaceHolder_rblstRole_8">Agency VP</label>
  <br>
  <input id="ctl00_ctl00_MainContent_ContentPlaceHolder_rblstRole_9" type="radio" name="ctl00$ctl00$MainContent$ContentPlaceHolder$rblstRole" value="13">
  <label for="ctl00_ctl00_MainContent_ContentPlaceHolder_rblstRole_9">Agent</label>
...
Jonathan Kittell
  • 7,163
  • 15
  • 50
  • 93
  • 1
    You should use the ClientId (https://msdn.microsoft.com/en-us/library/system.web.ui.control.clientid%28v=vs.110%29.aspx) property. <%: rblstRole.ClientId%> or similar. – Der Kommissar Apr 20 '15 at 19:23
  • An alternative to what EBrown said, you can change the radio button's `ClientIDMode` to static so that the ID won't change even if the location moves. – mason Apr 20 '15 at 19:31
  • 2
    add a class so ID becomes irrelevant – charlietfl Apr 20 '15 at 19:31

1 Answers1

3

You can use attribute selector of jQuery:

$('input[value="36"]').is(':checked')

and you can see the working demo here: http://jsfiddle.net/5637csyz/

Caner Akdeniz
  • 1,862
  • 14
  • 20