Click here to Skip to main content
15,897,291 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
I have mutiple radio buttons on my partial page, I also have one button on the same page
I am assigning radio button like this

C#
var rbSeq = 1;
foreach(var item in Model){
 @Html.RadioButtonFor(modelItem => item.YesNoNA[rbSeq], "true", new { id = "rb_YesNotrue" + rbSeq }) 
rbSeq++;
}


Now on click of Button I want to find all the radio button elements.

Thanks,
Rachana
Posted
Comments
Karthik. A 16-Jul-12 16:28pm    
Can you elaborate "Now on click of Button I want to find all the radio button elements" ? Using jquery/javascript or in the action method?
Sergey Alexandrovich Kryukov 16-Jul-12 18:15pm    
...and don't forget to ask a question.
--SA

1 solution

you can easily find all radio buttons using jquery:

JavaScript
$('input[type="radio"]').each();


So if you want to do something with your radiobuttons after clicking a button then:

ASP.NET
<asp:button id="myButton" runat="server" onclientclick="doSomWork()" />

JavaScript
<script type="text/javascript">
function doSomeWork(){
  $('input[type="radio"]').each(function(){
     // iterates all radio buttons
     var radioButton = $(this)
     // do something with the current radiobutton...
  });
}
</script>


The easiest way to implement jquery is to add this script reference in your head section:

HTML
<link rel="stylesheet" type="text/css" href="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" />
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900