Answered by:
jquery for radio buttons

Question
-
User219039814 posted
I have two radio buttons, I need to check which radio button is selected and take the value in code behind to work further..
<input type="radio" id="Radio1" name="choiceDDL" value ="Batch Wise View" runat="server" /> Batch Wise
<input type="radio" id="Radio2" name ="choiceDDL" value ="Year Wise View" runat="server" /> Year Wisecan someone help me..
Saturday, May 19, 2018 5:47 AM
Answers
-
User-474980206 posted
var v = $(“[name]=choiceDDL option:checked”).val();- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, May 19, 2018 6:31 PM -
User-369506445 posted
hi
if you want check it client side , please try below code :
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script> $(document).ready(function () { $(':radio').change(function () { alert($(this).val()); }); }); </script> </head> <body> <form runat="server"> <input type="radio" id="Radio1" name="choiceDDL" value="Batch Wise View" runat="server" /> Batch Wise <input type="radio" id="Radio2" name="choiceDDL" value="Year Wise View" runat="server" /> Year Wise </form> </body> </html>
or if you want check it in server side , please try below code
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script> $(document).ready(function () { $(':radio').change(function () { alert($(this).val()); }); }); </script> </head> <body> <form runat="server"> <input type="radio" id="Radio1" name="choiceDDL" value="Batch Wise View" runat="server" /> Batch Wise <input type="radio" id="Radio2" name="choiceDDL" value="Year Wise View" runat="server" /> Year Wise <asp:Button runat="server" ID="btn" Text="Submit" OnClick="btn_Click" /> </form> </body> </html>
protected void btn_Click(object sender, EventArgs e) { if (Radio1.Checked) { Response.Write(Radio1.Value); }else { Response.Write(Radio2.Value); } }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, May 20, 2018 5:17 AM
All replies
-
User-474980206 posted
var v = $(“[name]=choiceDDL option:checked”).val();- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, May 19, 2018 6:31 PM -
User-369506445 posted
hi
if you want check it client side , please try below code :
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script> $(document).ready(function () { $(':radio').change(function () { alert($(this).val()); }); }); </script> </head> <body> <form runat="server"> <input type="radio" id="Radio1" name="choiceDDL" value="Batch Wise View" runat="server" /> Batch Wise <input type="radio" id="Radio2" name="choiceDDL" value="Year Wise View" runat="server" /> Year Wise </form> </body> </html>
or if you want check it in server side , please try below code
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script> $(document).ready(function () { $(':radio').change(function () { alert($(this).val()); }); }); </script> </head> <body> <form runat="server"> <input type="radio" id="Radio1" name="choiceDDL" value="Batch Wise View" runat="server" /> Batch Wise <input type="radio" id="Radio2" name="choiceDDL" value="Year Wise View" runat="server" /> Year Wise <asp:Button runat="server" ID="btn" Text="Submit" OnClick="btn_Click" /> </form> </body> </html>
protected void btn_Click(object sender, EventArgs e) { if (Radio1.Checked) { Response.Write(Radio1.Value); }else { Response.Write(Radio2.Value); } }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, May 20, 2018 5:17 AM -
User36583972 posted
Hi vijaylakshmi,
I have two radio buttons, I need to check which radio button is selected and take the value in code behind to work further..jquery for radio buttonsIf you want to get the radio value using jquery and pass pass it to the code behind. You can refer the following samples.
How can I know which radio button is selected via jQuery?
https://stackoverflow.com/questions/596351/how-can-i-know-which-radio-button-is-selected-via-jqueryCalling ASP.Net WebMethod using jQuery AJAX:
https://www.aspsnippets.com/Articles/Calling-ASPNet-WebMethod-using-jQuery-AJAX.aspx
Best Regards,Yong Lu
Monday, May 21, 2018 7:47 AM