Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Web Technology by (20.3k points)

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?

1 Answer

0 votes
by (40.4k points)

Use the code given below to get the value of the selected radioName item of the form with id myForm:

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

For example:

$('#myForm input').on('change', function() {

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


<script src=""></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 />


Related questions

Browse Categories