Jquery get value from Radio Button

You need to change the value of category every time a user changes the selected radio button. Therefore you will need an event to trigger when the user clicks on a radio.

Demo


Fruit Name :



HTML

<form>
        <input type="radio" name="category" value="apple" id="apple" checked /> <label for="apple">Apple</label>
        <input type="radio" name="category" value="orange" id="orange" /> <label for="orange">Orange</label>
</form>
<br>
<h2>Fruit Name :</h2>
<div class="fruitName"></div>

Jquery

var category = null;
$("input[name='category']").click(function() {
    category = this.value;
    $('.fruitName').html(category)
});
  • Share
  • Copyright 2016 by WebiBeris.com. All Rights Reserved.