How to get selected radio button value in Jquery?
In this post we will give you information about How to get selected radio button value in Jquery?. Hear we will give you detail about How to get selected radio button value in Jquery?And how to use it also give you demo for it if it is necessary.
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" value="male"> Male
<input type="radio" name="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" value="male"> Male
<input type="radio" name="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" value="male"> Male
<input type="radio" name="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…
Hope this code and post will helped you for implement How to get selected radio button value in Jquery?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs