ItSolutionStuff.com

How to Get Selected Radio Button Value in JQuery?

By Hardik Savani • July 6, 2023
jQuery

Sometime we need to get selected value of radio button on click event or change event in jquery. it is a very small thing but if you then you can easily get selected radio button value by class or id on click event in jquery. we almost need to use radio button for male and female in our form.

i will give you 3 example of getting selected radio button value by class or id with click event or change event in js. we will use "checked" attribute to getting selected radio button value.

Let's see both example for getting select value of radio button in jquery.

Example 1:

<!DOCTYPE html>

<html>

<head>

<title>How to get selected radio button value in Jquery? - ItSolutionStuff.com</title>

<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>

</head>

<body>

<input type="radio" name="sex" class="sex" value="male"> Male

<input type="radio" name="sex" class="sex" value="female"> Female

<button>Click to redirect</button>

<script type="text/javascript">

$("button").click(function(){

var selValue = $("input[type='radio']:checked").val();

console.log(selValue);

});

</script>

</body>

</html>

Example 2:

<!DOCTYPE html>

<html>

<head>

<title>How to get selected radio button value in Jquery? - ItSolutionStuff.com</title>

<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>

</head>

<body>

<input type="radio" name="sex" class="sex" value="male"> Male

<input type="radio" name="sex" class="sex" value="female"> Female

<button>Click to redirect</button>

<script type="text/javascript">

$("button").click(function(){

var selValueByClass = $(".sex:checked").val();

console.log(selValueByClass);

});

</script>

</body>

</html>

Example 3:

<!DOCTYPE html>

<html>

<head>

<title>How to get selected radio button value in Jquery? - ItSolutionStuff.com</title>

<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>

</head>

<body>

<input type="radio" name="sex" class="sex" value="male"> Male

<input type="radio" name="sex" class="sex" value="female"> Female

<button>Click to redirect</button>

<script type="text/javascript">

$(".sex").change(function(){

var selValue = $("input[type='radio']:checked").val();

console.log(selValue);

});

</script>

</body>

</html>

I hope it can help you...

Tags: jQuery
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

JQuery Moment Get Current Date Example

Read Now →

JQuery Remove Multiple Values from Array Example

Read Now →

How to Remove Element from Array in JQuery?

Read Now →

JQuery Redirect to Another Page After 5 Seconds Example

Read Now →

How to Get Last Element from Array using JQuery?

Read Now →

How to Remove Empty or Null Values from JSON using JQuery?

Read Now →

How to Remove All Spaces from String in JQuery?

Read Now →

How to Remove Specific Value from Array in JQuery?

Read Now →

How to Remove undefined Value from Array in JQuery?

Read Now →

Automatically Scroll to Bottom of Div JQuery Example

Read Now →

Check and Uncheck All Checkbox using JQuery Example

Read Now →

How to Allow Only One Checkbox Checked at a Time in JQuery?

Read Now →

How to Check Undefined, Empty and Null in JQuery?

Read Now →

How to Check Object is Empty or Not in JQuery?

Read Now →