I am creating an order form that is populated by a .dat file. Each item appears in a separate table row with alternating red and gray background colors. Each row lists the item's name, price, and offers a dropdown to choose the quantity ordered.
I also want there to be a small input box that tells how much the person owes according to the quantity (1-10) they select from the dropdown. However, the boss wants the cost to change without having to press the submit button first (i.e., choose a number from the select box, and the input cost box automatically changes).
The problem I am having is that the price is generated in the for loop that pulls info from the dat file. Am I making any sense?
The code looks like this:
/* alternate bgcolor in a table */
function useColor(){
/* remember the last color we used */
static $ColorValue;
/* choose the next color */
if($ColorValue == "#990000"){
$ColorValue = "#c0c0c0";
}
else{
$ColorValue = "#990000";
}
return($ColorValue);
}
/* print table header */
print "<center><a name=\"taste\" href=\"tasteoftexas.htm\"><img src=\"totop.gif\" width=\"411\" height=\"87\" border=\"0\"></a>\n";
print "<table width=\"600\" cellpadding=\"3\" cellspacing=\"3\" border=\"0\">\n";
/* print taste of texas content */
$products = file("taste_of_texas.dat");
for ($i=0; $i<count($products); $i++){
$products[$i] = stripslashes($products[$i]);
$info = explode("|", $products[$i]);
$title = $info[0];
$productname = $info[1];
$price = $info[2];
/* get color for this row */
$RowColor = useColor();
/* print out HTML for row and set bgcolor */
print "<tr>\n";
print "<td bgcolor=\"$RowColor\" width=\"425\"><font face=\"arial\" color=\"#ffffff\" size=\"-1\"><b>$title</b><br>\n";
print "$productname</font></td>\n";
print "<td bgcolor=\"$RowColor\" width=\"100\"><font face=\"arial\" color=\"#ffffff\" size=\"-1\"><b>Quantity:\n";
/* set variable for quantity */
$product_quantity = $productname . "quantity";
print "<select name=\"$product_quantity\">\n";
for($count=0; $count < 10; $count++)
{
print "<option value=\"$count\"";
if ($product_quantity == '$count'){ print(" selected"); }
print ">$count\n";
}
print "</select></b><br>\n";
print " </font></td>\n";
print "<td align=\"center\" bgcolor=\"$RowColor\" width=\"75\"><font face=\"arial\" color=\"#ffffff\" size=\"-1\"><b>\n";
/* set variable for cost */
$cost = $price * $quantity;
print "$cost";
}
/* print table footer */
print "</table></center>\n";
print "<p align=\"center\">\n";
print "<font face=\"arial\" size=\"-1\"><a href=\"#order\">Place Order</a></font>\n";