How to Get Selected Radio Button Value in jQuery

/ / 0 Comments

jQuery get radio button value: This article explains how to check whether the radio button is checked or unchecked or getting the selected radio button value. In this post will explain how to check status of radio button i.e. whether radio button is checked or unchecked in jQuery. Here we use .is() method and matched checked attribute.

Description: .is() Check the current matched set of elements against a selector, element, or jQuery object and return true if at least one of these elements matches the given arguments.

HTML
:

<input name="gender" type="radio" id="rdoMale"><label> Male</label>
<input name="gender" type="radio" id="rdoFemale"><label>Female</label> <button id="btnGenderStatus">Click me</button>

JQUERY:

//*
var rdM = $("#rdoMale");
var rdF = $("#rdoFemale");
$("#btnGenderStatus").on('click', function () {
    if ($(rdM).is(":checked")) {
        console.log("You selected Male");
    } else if ($(rdF).is(":checked")) {
        console.log("You selected female");
    }
});
//*
VIEW DEMO

Thank you for reading, pls keep visiting this blog and share this in your network. Also, I would love to hear your opinions down in the comments.

PS: If you found this content valuable and want to do a favor, then Buy me a coffee

Subscribe to our newsletter

Get the latest and greatest from Codepedia delivered straight to your inbox.


Post Comment

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

0 Comments