Java Reference
In-Depth Information
}
function findIndexOfSpeed(radio) {
var radios = myForm.radCpuSpeed;
for (var index = 0; index < radios.length; index++) {
if (radios[index] == radio) {
return index;
}
}
return -1;
}
function radCpuSpeedClick(e) {
var radIndex = findIndexOfSpeed(e.target);
if (radIndex == 1) {
e.preventDefault();
alert("Sorry that processor speed is currently unavailable");
// to fix an issue with IE
myForm.radCpuSpeed[0].checked = true;
}
}
function btnCheckClick() {
var numberOfControls = myForm.length;
var compSpec = "Your chosen processor speed is ";
compSpec = compSpec + getSelectedSpeedValue();
compSpec = compSpec + "\nWith the following additional components:\n";
for (var index = 0; index < numberOfControls; index++) {
var element = myForm[index];
if (element.type == "checkbox") {
if (element.checked) {
compSpec = compSpec + element.value + "\n";
}
}
}
alert(compSpec);
}
for (var index = 0; index < myForm.radCpuSpeed.length; index++) {
myForm.radCpuSpeed[index].addEventListener("click", radCpuSpeedClick);
}
myForm.btnCheck.addEventListener("click", btnCheckClick);
</script>
</body>
</html>
Save the page as ch11 _ example6.html and load it into your web browser. You should see a form like
the one shown in Figure 11-7.
Search WWH ::




Custom Search