How I can radio button checked using index..
Below is my asp.net C# code for radion button list…
<asp:RadioButtonList runat="server" ID="rdlCategory" CssClass="clsradio" AppendDataBoundItems="true" RepeatDirection="Horizontal" RepeatLayout="Flow" >
</asp:RadioButtonList>
and Bind it using C# dynamically..
and Html looks like
<span class="clsradio" id="ctl00_cphTop_rdlCategory"><input type="radio" value="8" name="ctl00$cphTop$rdlCategory" id="ctl00_cphTop_rdlCategory_0">
<label for="ctl00_cphTop_rdlCategory_0">category1</label>
<input type="radio" value="11" name="ctl00$cphTop$rdlCategory" id="ctl00_cphTop_rdlCategory_1">
<label for="ctl00_cphTop_rdlCategory_1">category2</label>
<input type="radio" value="22" name="ctl00$cphTop$rdlCategory" id="ctl00_cphTop_rdlCategory_2">
<label for="ctl00_cphTop_rdlCategory_2">category3</label>
<input type="radio" value="33" name="ctl00$cphTop$rdlCategory" id="ctl00_cphTop_rdlCategory_3">
<label for="ctl00_cphTop_rdlCategory_3">category4</label>
<input type="radio" value="34" name="ctl00$cphTop$rdlCategory" id="ctl00_cphTop_rdlCategory_4">
<label for="ctl00_cphTop_rdlCategory_4">category5</label>
</span>
I want to add attribute checked=true to radio button by index value .
suppose, I passed index=2 then it should be selected Category2 ..
or also want to get selected (checked=true) radio button index using in jquery..
How I do this?
Unlike select boxes, there isn’t really a concept of an index in radio buttons.
However you can do something like this in jQuery:
Which will get all the input boxes within your span that are checked (which as your using radio’s should only be one, if only one group is inside .clsradio).
Here is an example on jsfiddle
EDIT:
A more full proof example (but slower) would be:
Which gets inputs ending in rdlCategory. You could even add “:radio” but you don’t need to.
EDIT 2 – Checking by passing in index.
You can use:
nth-child using the “input” selector can be used as the index.