Hello again,
I'm a bit stumped on some coding. What I am wanting to do is to validate that both a checkbox is checked and a quantity is entered. Here's my form code:
$ix = 0; // form field index counter
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo '<tr><td align="left">' . $row['category'] . '</td>
<td align="left"><input type="checkbox" name="od['.$ix.'][selection]" value="' . $row['dn'] .'"></td>
<td align="left"><input type="text" name="od['.$ix.'][qty]" id="od_' .
$row['d1'] . '_' . $row['price'] . '" size="2" onchange="CalculateTotal(this.form)"></td>
<td align="left">' . $row['dn'] . '</td>
<td align="left">' . $row['dd'] . '</td>
<td align ="right">' . $row['price'] . '</td></tr>';
$ix++; // increment index
}
I have 2 options that I want to do and must compare the 2 fields:
1) If a qty >0 is entered, then set the checkbox to checked or
2) If the checkbox is checked then set the qty to 1 as a default but still can enter any qty.
I've tried several things but nothing is working and I'm fairly sure it is because I'm not writing the variable for these correctly or not in the right place. The array values are set in a foreach statement in the process_form script:
// Get the order, print it and send to the database
foreach($_POST['od'] as $order)
{
$qty = $order['qty'];
$sel = $order['selection'];
if ($qty > 0) { // Don't send zero values
echo ' ' . $qty . ' ' . $sel . ' <br />';
$query = "INSERT INTO order_details (od_id, order_id, dish_name, od_qty, order_date) VALUES ('', '$oid', '$sel', '$qty', NOW())";
Any help would be appreciated. BTW you guys helped me on this code before and I got the rest working. Thanks for that!