Monday, 21 August 2017

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

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

Description:

In this example we explain that how to check  if RadioButton (RadioGroup) is checked or not using JavaScript.or how to check if RadioButtion or RadioButtonList is selected or not selected using JavaScript.

Code:


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <script type="text/javascript">
     function ShowHideDiv() {
         var chkYes = document.getElementById("chkYes");
         var dvReference = document.getElementById("dvReference");
         dvReference.style.display = chkYes.checked ? "block" : "none";
     }
</script>
    <title>Check if a RadioButton (RadioGroup) is checked or not using JavaScript</title>
</head>
<body>
 
<span>Do you have any Reference?</span>
<label for="chkYes">
    <input type="radio" id="chkYes" name="chkreference" onclick="ShowHideDiv()" />
    Yes
</label>
<label for="chkNo">
    <input type="radio" id="chkNo" name="chkreference" onclick="ShowHideDiv()" />
    No
</label>
<hr />
<div id="dvReference" style="display: none">
   Reference Name:
    <input type="text" id="txtreference" />
</div>
</body>
</html>




0 comments:

Post a Comment