Tuesday, 15 August 2017

Check if a RadioButton (RadioGroup) is checked or not using jQuery

Check if a RadioButton (RadioGroup) is checked or not using jQuery

Description:

In this example we explain that how to check if Radio Button is checked or not using jQuery. Or how to get the value of the Radio Button using jQuery. Or how to check or unchecked the radio button using jQuery. Or how to check if Radio Button is select or deselect using jQuery.


Code:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("input[name='chkReference']").click(function () {
            if ($("#chkYes").is(":checked")) {
                $("#dvReference").show();
            } else {
                $("#dvReference").hide();
            }
        });
    });
</script>
<span>Do you have any Reference ?</span>
<label for="chkYes">
    <input type="radio" id="chkYes" name="chkReference" />
    Yes
</label>
<label for="chkNo">
    <input type="radio" id="chkNo" name="chkReference" />
    No
</label>
<hr />
<div id="dvReference" style="display: none">
    Reference:
    <input type="text" id="txtReference" />
</div>



0 comments:

Post a Comment