An onclick Event Handler for Radio Buttons : Radio Button « Form « JavaScript Tutorial






<html> 
<head> 
<title>Radio Button onClick Handler</title> 
<script type="text/javascript"> 
var myFlag = false 
function initValue() { 
    myFlag = document.forms[0].sizes[0].checked; 
} 
function sh(form) { 
    for (var i = 0; i < form.sizes.length; i++) { 
        if (form.sizes[i].checked) { 
            break; 
        } 
    } 
    alert(form.sizes[i].value); 
} 
function setmyFlag(setting) { 
    myFlag = setting; 
} 
function exitMsg() { 
    if (myFlag) { 
        alert("exit message."); 
    } 
} 
</script> 


</head> 
<body onload="initValue()" onunload="exitMsg()"> 
<form> 
    <input type="radio" name="sizes" value="1" checked="checked" onclick="setmyFlag(true)" />1
    <input type="radio" name="sizes" value="2" onclick="setmyFlag(false)" />2 
    <input type="radio" name="sizes" value="7" onclick="setmyFlag(false)" />7
    <input type="radio" name="sizes" value="5" onclick="setmyFlag(false)" />5
    <input type="button" name="Viewer" value="View" onclick="sh(this.form)" /></p> 
</form> 
</body> 
</html>








10.11.Radio Button
10.11.1.Radio
10.11.2.Radio.blur()
10.11.3.Radio.checked
10.11.4.Radio.click()
10.11.5.Radio.defaultChecked
10.11.6.Radio.focus()
10.11.7.Radio.form
10.11.8.Radio.handleEvent()
10.11.9.Radio.name
10.11.10.Radio.onBlur
10.11.11.Radio.onClick
10.11.12.Radio.onFocus()
10.11.13.Radio.type
10.11.14.Radio.value
10.11.15.Checking a Radio Button Group
10.11.16.With with RADIO and CheckBox
10.11.17.Cycle the selected radio buttons
10.11.18.An onclick Event Handler for Radio Buttons