• support@answerspoint.com

How can I know which radio button is selected via jQuery?

613

I have two radio buttons and want to post the value of the selected one. How can I get the value with jQuery?

I can get all of them like this:

$("form :radio")

How do I know which one is selected?

2Answer


0

To get the value of the selected radioName item of a form with id myForm:

$('input[name=radioName]:checked', '#myForm').val()

Here's an example:

 

$('#myForm input').on('change', function() {
   alert($('input[name=radioName]:checked', '#myForm').val()); 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="myForm">
<input type="radio" name="radioName" value="1" /> 1 <br />
<input type="radio" name="radioName" value="2" /> 2 <br />
<input type="radio" name="radioName" value="3" /> 3 <br />
  • answered 3 years ago
  • Sunny Solu

0

Use this..

$("#myform input[type='radio']:checked").val();
  • answered 3 years ago
  • Sunny Solu

Your Answer

    Facebook Share        
       
  • asked 3 years ago
  • viewed 613 times
  • active 3 years ago

Hot Questions