...

View Full Version : Checkboxes and TextBoxes...



pavmoxo
08-21-2006, 04:55 PM
Greetings at all!!!

I have a problem that I know the reason but I didn't yet discover how to fix it:

In an e-commerce development I show a series of products dinamically and they have a checkbox for select each one if I wan't to buy them. I tried to implement a textbox for input a quantity but I canīt correspond the checkboxes array and the textboxes array. If I substitute the textboxes with checkboxes with diferent values they match. I discuss the issue with a friend and he tell me that the check and text boxes can have diferent sizes. My point is: how can I resolve this for select the products, input a quantity for show the final price?? I need a example because I don't am very good in programming...can you help me??

mlseim
08-21-2006, 05:05 PM
This is one where we really need to see the website so we can see
what you're doing. Or at least post the form you're using and maybe
the first 50 lines of the PHP script (something like that) ... would help
us to help you.

devinemke
08-21-2006, 05:18 PM
a simple example:


<?php
$products = array(
1 => array('name' => 'Broadband Router', 'price' => 150.00),
2 => array('name' => 'Ethernet Card', 'price' => 15.30),
3 => array('name' => 'CPU', 'price' => 330.50),
4 => array('name' => 'Cooling Fan', 'price' => 26.99),
5 => array('name' => 'Grilled Cheese Sandwich', 'price' => 4.95)
);

if (!isset($_POST['submit']))
{
echo '<form action="" method="POST">';

foreach ($products as $key => $value)
{
echo 'qty: <input type="text" name="qty[' . $key . ']" value="0" size="2"> ' . $value['name'] . ' ($' . $value['price'] . ')<br>';
}

echo '
<input type="submit" name="submit" value="submit">
</form>
';
}
else
{
$total = 0;
foreach ($_POST['qty'] as $key => $value)
{
if ($value)
{
$subtotal = $value * $products[$key]['price'];
$total += $subtotal;
echo $value . ' x ' . $products[$key]['name'] . ': subtotal = $' . number_format($subtotal, 2) . '<br>';
}
}
echo '<br>total = $' . number_format($total, 2);
}
?>

pavmoxo
08-21-2006, 05:47 PM
I will try this last POST. Thanks a lot!! ...but I leave some lines of code of in case... better...there is a post mine:

http://www.dynamicdrive.com/forums/showthread.php?t=11936

thanks!!!

pavmoxo
08-22-2006, 10:47 AM
I don't know how to modify my code in the form. it's diferent that the solution above!! Can You help???

I leave another post:

http://www.codingforums.com/showthread.php?t=93727

I'm sorry for booring you!!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum