9.9 Write an HTML document to create a form with the following capabilities: a.
ID: 3671587 • Letter: 9
Question
9.9 Write an HTML document to create a form with the following capabilities: a. A text widget to collect the user's name b. Four checkboxes, one each for the following items: i. Four 25-watt light bulbs for $2.39 ii. Eight 25-watt light bulbs for $4.29 iii. Four 25-watt long-life light bulbs for S3.95 iv. Eight 25-watt long-life light bulbs for $7.49 c. A collection of three radio buttons that are labeled as follows 1. V1sa ii. Master Card iii. Discover 9.10 Write a PHP script that computes the total cost of the ordered light bulbs from Exercise 9.9 after adding 6.2 percent sales tax. The program must inform the buyer of exactly what was ordered, in a table.Explanation / Answer
one.html
<!DOCTYPE html>
<html lang = "en">
<head>
<title> html </title>
<meta charset = "utf-8" />
</head>
<body>
<form action = "one.php" method = "post">
<p>
<!-- Label and textbox for username -->
<label> User Name: <input name = "txtUserName" type="text" size = "30"/></label>
<br />
<label> <input name = "chkBulbs1" type="checkbox" value = "2.39" /> Four 25-watt light bulbs $2.39</label>
<br />
<label> <input name = "chkBulbs2" type="checkbox" value = "4.29" /> Eight 25-watt light bulbs $4.29</label>
<br />
<label> <input name = "chkBulbs3" type="checkbox" value = "3.95" /> Four 25-watt long-life light bulbs $3.95</label>
<br />
<label> <input name = "chkBulbs4" type="checkbox" value = "7.49" /> Eight 25-watt long life light bulbs $7.49</label>
<br />
<br />
<label> <input name = "payment" type="radio" value = "Visa" /> Visa </label>
<br />
<label> <input name = "payment" type="radio" value = "Master Card" /> Master Card </label>
<br />
<label> <input name = "payment" type="radio" value = "Discover" /> Discover </label>
<br />
<!-- Submit/Reset Buttons -->
<input type = "submit" name = "submit" value = "Submit"/>
<input type = "reset"/>
</p>
</form>
</body>
</html>
one.php
<!DOCTYPE html>
<html lang = "en">
<head>
<title> PHP</title>
</head>
<body>
<h1>PHP</h1>
<?php
$SALES_TAX = .062;//6.2 percent sales tax
$bulbLabels = array("Four 25-watt light bulbs",
"Eight 25-watt light bulbs",
"Four 25-watt long-life light bulbs",
"Eight 25-watt long life light bulbs");
// $bulbCost = array($_POST["chkBulbs1"],
// $_POST["chkBulbs2"],
// $_POST["chkBulbs3"],
// $_POST["chkBulbs4"]);
$total = 0.00;
$userName = $_POST["txtUserName"];
$payment = $_POST["payment"];
//Found something online where the previous page could return an array
//by changing name = "chkSomething" to name = "chkSomething[]", doesn't
//seem to work very well in practice.
print "<table>";
// for($i = 0 ; $i < count($bulbLabels) ; $i++){
// //Don't put assignments in the parameters of if statements like other langs
// if(isset($bulbCost[$i])){
// //print the table
// print "<tr><td>" . $bulbLabels[$i] . "</td><td>" . $bulbCost[$i] . "</td></tr>";
// //accumulate the total
// $total += (float)$bulbCost[$i] + (float)$bulbCost[$i] * $SALES_TAX;
// }
// }//end loop
if(isset($userName) && isset($payment)){
//display userName type
print "<h3>User Name: " . (string)$userName . "</h3>";
$bulbCost = $_POST["chkBulbs1"];
if(isset($bulbCost)){
print "<tr><td>" . $bulbLabels[0] . "</td><td>" . $bulbCost . "</td></tr>";
$total += (float)$bulbCost + (float)$bulbCost * $SALES_TAX;
}
$bulbCost = $_POST["chkBulbs2"];
if(isset($bulbCost)){
print "<tr><td>" . $bulbLabels[1] . "</td><td>" . $bulbCost . "</td></tr>";
$total += (float)$bulbCost + (float)$bulbCost * $SALES_TAX;
}
$bulbCost = $_POST["chkBulbs3"];
if(isset($bulbCost)){
print "<tr><td>" . $bulbLabels[2] . "</td><td>" . $bulbCost . "</td></tr>";
$total += (float)$bulbCost + (float)$bulbCost * $SALES_TAX;
}
$bulbCost = $_POST["chkBulbs4"];
if(isset($bulbCost)){
print "<tr><td>" . $bulbLabels[3] . "</td><td>" . $bulbCost . "</td></tr>";
$total += (float)$bulbCost + (float)$bulbCost * $SALES_TAX;
}
print "</table> ";
//display the total
print "<h3>Total: " . (string)round($total, 2) . "</h3>";
//display payment type
print "<h3>Payment Type: " . (string)$payment . "</h3>";
}
else {//username and payment not set
print "<h3>Please fill out form correctly...</h3>";
}
?>
</body>
</html>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.