Java Reference
In-Depth Information
Finally, you have the case type. Because only one case type out of the options can be selected, you used
a radio button group. Unfortunately, there is no selectedIndex for radio buttons as there is for check
boxes, so you have to go through each radio button in turn and fi nd out if it has been selected.
formElement = theForm.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]);
}
You check to see which radio button the user selected and add its details to the textarea and its price
to the total. If the array of stock defi ned at the beginning of the code block had further details, such
as description as well as price, you could have looped through the radio button array and added the
details based on the compItems array.
Finally, set the textarea to the details of the system the user has selected.
orderDetails = orderDetails + “\n\nTotal Order Cost is “ + total;
theForm.txtOrder.value = orderDetails;
Chapter 8
Exercise 1 Question
In the previous chapter's exercise questions, you created a form that allowed the user to pick a computer
system. They could view the details of their system and its total cost by clicking a button that wrote the
details to a textarea. Change the example so it's a frames-based web page; instead of writing to a text
area, the application should write the details to another frame. Hint: use about:blank as the src of the
frame you write to. Hint: use the document object's close() and open() methods to clear the details
frame from previously written data.
Exercise 1 Solution
The solution shown here involves a frameset that divides the page into left and right frames. In the left
frame displays the form that allows the user to pick their system. A summarization of the user's choices
display in the right frame when the user clicks an Update button.
Search WWH ::




Custom Search