more book code issues
chapter 6 page 208
the following code does not reset the radCPUSpeed radio button as described on page 212. If option 1GZh is selected.
Any help would be appreciated. Here is the code from the book
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language=javascript>
var radCpuSpeedIndex = 0;
function radCPUSpeed_onclick(radIndex)
{
var returnValue = true;
if (radIndex == 1) //if index is 1 we are out ot that item and return false which
{ //cancels the action
returnValue = false;
alert("We are out of that one ");
document.form1.radCPUSpeed[radCpuSpeedIndex].checked = true; //reset
}
else
{
radCpuSpeedIndex = radIndex;
alert(radCpuSpeedIndex);
}
return returnValue;
}
function butCheck_onclick()
{
var controlIndex;
var element;
var numberOfControls = document.form1.length;
var compSpec = "Your chosen processor speed is ";
compSpec = compSpec + document.form1.radCPUSpeed[radCpuSpeedIndex].value;
compSpec = compSpec + "\nWith the following additional components\n";
for(controlIndex = 0; controlIndex < numberOfControls; controlIndex++)
{
element = document.form1[controlIndex]
if(element.type == "checkbox")
{
if(element.checked == true)
{
compSpec = compSpec + element.value + "\n";
}
}
}
alert(compSpec);
}
</script>
</head>
<body>
<form name=form1>
<P>
Tick all the components you want included in your computer<BR><BR>
<table>
<tr><TD>DVD</td><td><input type=checkbox name=chkDVD value="DVD"></td>
</tr>
<tr><TD>CD</td><td><input type=checkbox name=chkCD value="CD"></td>
</tr>
<tr><TD>Zip Drive</td><td><input type=checkbox name=chkZip value="ZIP"></td>
</tr>
</table>
<P>
Select the processor speed you require<P>
<table>
<tr>
<td><input type=radio name=radCPUSpeed checked
onclick="return radCPUSpeed_onclick(0)" value="800 MHz"></td>
<td>800MZh</td>
<td><input type=radio name=radCPUSpeed
onclick="return radCPUSpeed_onclick(1)" value="1 GHz"></td>
<td>1 GHz</td>
<td><input type=radio name=radCPUSpeed
onclick="return radCPUSpeed_onclick(2)" value="1.5 GHz"></td>
<td>1.5 GHz</td>
</tr></table>
</TABLE>
<P>
<P>
<input type=button value="Check form" name=butCheck onclick="return butCheck_onclick()">;
</form>
</body>
</html>
|