How to get selected radio button value on change in jquery

November 4, 2021
Jquery
How to get selected radio button value on change in jquery

In this tutorial, you will get to know how to get the selected radio value on the change event in jquery.

This is one of the common things is to get the value of selected radio button when the radio button changed or selected.

Let’s jump to the solution.

Creating the radio buttons

Let’s say, we have two radio buttons for food with pizza and a burger.

<input type="radio" name="food" class="food" value="pizza"> Pizza
<input type="radio" name="food" class="food" value="burger"> Burger

Get value of selected radio button on change

In the following code, we are looking for the change in the food buttons. As soon as the option is selected or changed. It will trigger the changeevent and you will get the value of the selected radio button.

<script>

    $(".food").change(function(){
      let radio_value=$(".food:checked").val();
      console.log(radio_value);
    });
</script>

Conclusion:

Hope you have learned today how to get selected radio button value on change event in Jquery.

Questions are welcomed in the comments.

See you soon again!

Write a Reply or Comment

Your email address will not be published. Required fields are marked *


Icon