Java Reference
In-Depth Information
total = total + dvdInfo.price;
orderDetails = orderDetails + "DVD-ROM : $" +
dvdInfo.price + "\n";
}
var bluRayInfo = getCheckboxInfo(theForm.chkBluRay);
if (bluRayInfo.checked) {
total = total + bluRayInfo.price;
orderDetails = orderDetails + "Blu-ray : $" +
bluRayInfo.price + "\n";
}
var caseInfo = getRadioInfo(theForm.radCase);
total = total + caseInfo.price;
orderDetails = orderDetails + caseInfo.text + " : $" +
caseInfo.price;
orderDetails = orderDetails + "\n\nTotal Order Cost is " +
"$" + total;
theForm.txtOrder.value = orderDetails;
}
document.getElementById("btnUpdate")
.addEventListener("click", btnUpdateClick);
</script>
</script>
</body>
</html>
Save this as ch11 _ question2.html .
This is just one of many ways to tackle this question—you may well have thought of a
bet ter way.
Here you are displaying the results of the user's selection as text in a textarea box, with each item
and its cost displayed on separate lines and a final total at the end.
Each form element has a value set to hold a stock ID number. For example, a full tower case is stock
ID 402. The actual cost of the item is held in an array called productDb . Why not just store the
price in the value attribute of each form element? Well, this way is more flexible. Currently your
array just holds price details for each item, but you could modify it that so it holds more data—for
example price, description, number in stock, and so on. Also, if this form is posted to a server the
values passed will be stock IDs, which you could then use for a lookup in a stock database. If the
values were set to prices and the form was posted, you'd have no way of telling what the customer
ordered—all you'd know is how much it all cost.
Search WWH ::




Custom Search