Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Apr 2006
    Posts
    154
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Checkboxes and TextBoxes...

    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??

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,511
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    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.

  • #3
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    a simple example:
    PHP Code:
    <?php
    $products 
    = array(
    => array('name' => 'Broadband Router''price' => 150.00),
    => array('name' => 'Ethernet Card''price' => 15.30),
    => array('name' => 'CPU''price' => 330.50),
    => array('name' => 'Cooling Fan''price' => 26.99),
    => 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($subtotal2) . '<br>';
            }        
        }
        echo 
    '<br>total = $' number_format($total2);
    }
    ?>

  • #4
    Regular Coder
    Join Date
    Apr 2006
    Posts
    154
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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/s...ad.php?t=11936

    thanks!!!

  • #5
    Regular Coder
    Join Date
    Apr 2006
    Posts
    154
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •