topical media & game development

talk show tell print

basic-javascript-06-ch06-q2.htm / htm



  <html>
  <head>
  
  <script language="JavaScript" type="text/javascript">
  var CompItems = new Array();
  CompItems[100] = 1000;
  CompItems[101] = 1250;
  CompItems[102] = 1500;
  
  CompItems[200] = 35;
  CompItems[201] = 65;
  CompItems[202] = 95;
  
  CompItems[300] = 50;
  CompItems[301] = 75;
  CompItems[302] = 100;
  
  CompItems[400] = 10;
  CompItems[401] = 15;
  CompItems[402] = 25;
  function updateOrderDetails()
  {
     var total = 0;
     var orderDetails = "";
     var formElement;
     formElement = 
        document.form1.cboProcessor[document.form1.cboProcessor.selectedIndex];
     total = parseFloat(CompItems[formElement.value]);
     orderDetails = "Processor : " + formElement.text;
     orderDetails = orderDetails + " " + CompItems[formElement.value] + "\n";
  
     formElement = 
        document.form1.cboHardDrive[document.form1.cboHardDrive.selectedIndex];
     total = total + parseFloat(CompItems[formElement.value]);
     orderDetails = orderDetails + "Hard Drive : " + formElement.text;
     orderDetails = orderDetails + " " + CompItems[formElement.value] + "\n";
  
     formElement = document.form1.chkCDROM
     if (formElement.checked == true)
     {
        orderDetails = orderDetails + "CD-ROM : " +
           CompItems[formElement.value] + "\n";
        total = total + parseFloat(CompItems[formElement.value]);
     }
  
     formElement = document.form1.chkDVD
     if (formElement.checked == true)
     {
        orderDetails = orderDetails + "DVD-ROM : " + 
           CompItems[formElement.value] + "\n";
        total = total + parseFloat(CompItems[formElement.value]);
     }
  
     formElement = document.form1.chkScanner
     if (formElement.checked == true)
     {
        orderDetails = orderDetails + "Scanner : " + 
           CompItems[formElement.value] + "\n";
        total = total + parseFloat(CompItems[formElement.value]);
     }
  
     formElement = document.form1.radCase
     if (formElement[0].checked == true)
     {
        orderDetails = orderDetails + "Desktop Case : " + 
           CompItems[formElement[0].value];
        total = total + parseFloat(CompItems[formElement[0].value]);
     }
     else if (formElement[1].checked == true)
     {
        orderDetails = orderDetails + "Mini Tower Case : " + 
           CompItems[formElement[1].value];
        total = total + parseFloat(CompItems[formElement[1].value]);
     }
     else 
     {
        orderDetails = orderDetails + "Full Tower Case : " + 
           CompItems[formElement[2].value]
        total = total + parseFloat(CompItems[formElement[2].value]);
     }
  
     orderDetails = orderDetails + "\n\nTotal Order Cost is " + total;
  
     document.form1.txtOrder.value = orderDetails;
  }
  
  </script>
  </head>
  
  <body>
  <form name="form1">
  <table>
  <TR>
  <TD width="300">
  Processor
  <br>
  <select name=cboProcessor>
     <option value="100">MegaPro 10ghz</option>
     <option value="101">MegaPro 12</option>
     <option value="102">MegaPro 15ghz</option>
  </select>
  <br><br>
  Hard drive 
  <br>
  <select name=cboHardDrive>
     <option value="200">30tb</option>
     <option value="201">40tb</option>
     <option value="202">60tb</option>
  </select>
  <br><br>
  CD-ROM
  <input type="checkbox" name=chkCDROM value="300">
  <br>
  DVD-ROM
  <input type="checkbox" name=chkDVD value="301">
  <br>
  Scanner
  <input type="checkbox" name=chkScanner value="302">
  <br><br>
  Desktop Case
  <input type="radio" name=radCase checked value="400">
  <br>
  Mini Tower
  <input type="radio" name=radCase value="401">
  <br>
  Full Tower
  <input type="radio" name=radCase value="402">
  <P>
  <input type="button" value="Update" name=butUpdate onclick="updateOrderDetails()">
  </P>
  </TD>
  <TD>
  <textarea rows="20" cols="35" id=txtOrder name="txtOrder">
  </textarea>
  </TD>
  </TR>
  </table>
  </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.