Pages

Showing posts with label Radio Button. Show all posts
Showing posts with label Radio Button. Show all posts

Jquery Tutorial 2: How can I know which radio button is selected via jQuery?

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:

Index.html

<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 />
</form>

Javascript

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

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


Here You can replace input class name and radio details


Popular Posts