Java Reference
In-Depth Information
Exercise 2 Question
Create a user interface that allows the user to pick the computer system of their dreams, similar in prin-
ciple to the e-commerce sites selling computers over the Internet. For example, they could be given a
choice of processor type, speed, memory, and hard drive size, and the option to add additional compo-
nents like a DVD-ROM drive, a sound card, and so on. As the user changes their selections, the price of
the system should update automatically and notify them of the cost of the system as they specifi ed it,
either by using an alert box or by updating the contents of a text box.
Exercise 2 Solution
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Chapter 7: Question 1</title>
<script 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;
var theForm = document.form1;
formElement = theForm.cboProcessor[theForm.cboProcessor.selectedIndex];
total = parseFloat(compItems[formElement.value]);
orderDetails = “Processor : “ + formElement.text;
orderDetails = orderDetails + “ $” + compItems[formElement.value] + “\n”;
formElement = theForm.cboHardDrive[theForm.cboHardDrive.selectedIndex];
total = total + parseFloat(compItems[formElement.value]);
orderDetails = orderDetails + “Hard Drive : “ + formElement.text;
orderDetails = orderDetails + “ $” + compItems[formElement.value] + “\n”;
formElement = theForm.chkCDROM;
if (formElement.checked == true)
{
orderDetails = orderDetails + “CD-ROM : $” +
Search WWH ::




Custom Search