Introduction:

in this article I will explain how to use jQuery to check if radio button checked / selected or not. There are different methods to check whetehr radio button is selected / checked or not. By using radio button properties prop or attr.
I have discussed three Method
to find out whether radiobutton is selected or not:
Method 1:
var status = $('#rdbcheck:checked').val() ? true : false
Method 2:
var status = $('#rdbcheck').is(':checked');
Method 3:
var status = $('#rdbcheck').attr('checked') ? true : false;
Full Source Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Check radio button checked or
selected</title>
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function
() {
$('#btnSubmit').click(function () {
var
status = $('#rdbcheck').is(':checked');
alert(status)
})
});
</script>
</head>
<body>
<center>
<fieldset style="width:400px">
<legend><strong>jQuery Check radio button checked or selected</strong></legend>
<br /><br />
<b>Select Radio Button :</b>
<input type="radio"
id="rdbcheck"
value="India"
/>India
<button id="btnSubmit">Radio
Button Status</button>
<br /><br
/>
</fieldset></center>
</body>
</html>
0 comments:
Post a Comment