topical media & game development

talk show tell print

basic-javascript-06-ch6-examp6.htm / htm



  <html>
  <head>
  <script language="JavaScript" type="text/javascript">
  
  var radCpuSpeedIndex = 0;
   
  function radCPUSpeed_onclick(radIndex)
  {
     var returnValue = true;
     if (radIndex == 1)
     {
        returnValue = false;
        alert("Sorry that processor speed is currently unavailable");
        // Next line works around a bug in IE that doesn’t cancel the
        // Default action properly
        document.form1.radCPUSpeed[radCpuSpeedIndex].checked = true;
     }
     else
     {
        radCpuSpeedIndex = radIndex;
     }
     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 of the components you want included on your computer <br><br>
  <table> <tr>
     <td>DVD-ROM</td>
     <td><input type="checkbox" name="chkDVD" value="DVD-ROM"></td>
  </tr> <tr>
     <td>CD-ROM</td>
     <td><input type="checkbox" name="chkCD" value="CD-ROM"></td>
  </tr> <tr>
     <td>Zip Drive</td>
   
     <td><input type="checkbox" name="chkZip" value="ZIP Drive"></td>
  </tr>
  </table>
  <p>
  Select the processor speed you require <table>
  <tr>
     <td><input type="radio" name="radCPUSpeed" checked 
        onclick="return radCPUSpeed_onclick(0)" value="3.8 GHz"></td>
     <td>3.8 GHz</td>    <td><input type="radio" name="radCPUSpeed" 
        onclick="return radCPUSpeed_onclick(1)" value="4.8 GHz"></td>
     <td>4.8 GHz</td>
     <td><input type="radio" name="radCPUSpeed" 
        onclick="return radCPUSpeed_onclick(2)" value="6 Ghz"></td>
     <td>6 GHz</td> </tr>
  </table>
  </p> <input type="button" value="Check Form" name="butCheck" 
     onclick="return butCheck_onclick()">
  </form>
  </body>
  </html>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.