Welcome to %s forums

<No. 1 Community for developers, by developers/>

Login Register

How to know which radio button is selected using jQuery?

Get support on JavaScript,jQuery, AJAX and other related technology.
Post Reply
admin
Site Admin
Posts: 45

How to know which radio button is selected using jQuery?

Post by admin » Wed Oct 16, 2019 11:00 pm

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

Code: Select all

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


Here's an example:
Add jQuery if already added ignore below code-

Code: Select all

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Code: Select all

$('#myForm input').on('change', function() {
   alert($('input[name=radioName]:checked', '#myForm').val()); 
});
<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 />
</form>

Post Reply