<div>
<label for="rdb_disease">Are you okay?</label>
<div class="col-sm-9" class="rdb_disease">
<input type="radio" id="no" name="rdb_diseease" value="0">
<label for="no">No</label>
<input type="radio" id="yas" name="rdb_diseease" value="1">
<label for="yes">yes</label>
</div>
</div>
<div id="disease_panel">
<p>hello</p>
</div>
<script>
var rdb_disease = document.getElementById("rdb_disease");
function rdb_visible_hide_panel(rdb_name,panel_name) {
var radio = rdb_name.getElementsByTagName("input");
if (radio[1].checked == true) {
panel_name.style.display = "block";
} else {
panel_name.style.display = "none";
}
}
rdb_disease.addEventListener("change", function() {
rdb_visible_hide_panel(rdb_disease,disease_panel);
});
</script>
I see an error message (Uncaught TypeError: Cannot read property 'addEventListener' of null) I ithink the problem is (getElementsByTagName) But anyway it cannot reach Element what is the problem i want anser in thes problem
document.getElementById("rdb_disease")
yet there is not element with an ID attribute like that. You only have an element with this class. – VLAZrdb_disease
? There is only<label for="rdb_disease" ">are you okay</label>
This isn't a tag.for="rdb_disease" "
. – jacobkim