
Originally Posted by
kenoli
So this issue for me is what event is triggered when a radio button gets unchecked by another button being checked?
I'm not sure if an even trigger is fired for the radio button in this case.
I am still not exactly sure what you want to happen when each checkbox is clicked. It would help if you state exactly what you want to happen when a particular checkbox is clicked.
Guessing a bit as to what you want, the code below has your 2 radio buttons and checkboxes. Checkbox 1 clicks radio button 1 and checkbox 2 clicks radio button 2. When a radio button is clicked, either directly or indirectly by a checkbox, clickAction() checks each radio button to see whether it is now checked or unchecked and alerts an appropriate message.
Code:
<html>
<head>
<title></title>
<script type="text/javascript">
function clickAction() {
for(var i=0; i < radBtns.length; i++) {
if(radBtns[i].checked) {
alert(radBtns[i].id + ' is checked');
} else {
alert(radBtns[i].id + ' is unchecked');
}
}
}
function clickRadBtn(elemId) {
document.getElementById(elemId).click();
}
var radBtns = new Array();
window.onload=function() {
radBtns = document.getElementsByName('btnRad');
}
</script>
</head>
<body>
<input type="radio" name="btnRad" id="btnRad1" onclick="clickAction();" />Button one<br/>
<input type="radio" name="btnRad" id="btnRad2" onclick="clickAction();" />Button two<br/><br/>
<input type="checkbox" name="chkBox1" onclick="clickRadBtn('btnRad1')" />Box one<br/>
<input type="checkbox" name="chkBox2" onclick="clickRadBtn('btnRad2')" />Box two<br/><br/>
</body>
</html>
Bookmarks