How do I add the values of an array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • apryl
    New Member
    • Apr 2010
    • 2

    #1

    How do I add the values of an array

    I have php code that I am using on submit of a registration form that passes the number of checked "check boxes" counted for each array to a shopping cart as a product quantity.
    I want to modify that code to pass the value of "input textboxes" (for products where more than one can be purchased) for another array. right now no matter if 3 or 4 or 2 is typed into the form only 1 is being passed to the shopping cart.
    This is what works using check boxes. What should I change to use text input boxes?
    Code:
    $debug = false;
    $bqtyd_array = $bqtyw_array = $fqtyd_array = $fqtyw_array = $tentm_array = array();
    for ( $i = 0; $i <=5; $i++ ) {
        $bqtyd_array[$i] = JRequest::getBool('bqtyd'.$i, 'false', 'post');
        $bqtyw_array[$i] = JRequest::getBool('bqtyw'.$i, 'false', 'post'); 
        $fqtyd_array[$i] = JRequest::getBool('fqtyd'.$i, 'false', 'post');
        $fqtyw_array[$i] = JRequest::getBool('fqtyw'.$i, 'false', 'post');
    }
    for ( $n = 0; $n <=5; $n++ ) { 
        $tentm_array[$n] = JRequest::getBool('tentm'.$n, 'false', 'post');
    }
    if ($debug) {echo '<div>$tentm_array: '.print_r($tentm_array, true).'</div>';}
    $count['bsd'] = array_sum($bqtyd_array);
    $count['bsw'] = array_sum($bqtyw_array);
    $count['fcd'] = array_sum($fqtyd_array);
    $count['fcw'] = array_sum($fqtyw_array);
    $count['jrtm'] = array_sum($tentm_array);
    Thank you
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    you need to read the value of the text box, whereas you just seen to be evaluating whether it is used.
    A check box is not always set but a text box is.

    Comment

    • apryl
      New Member
      • Apr 2010
      • 2

      #3
      Thanks code green. I ended up adding the values of the input boxes with javascript and then modified my code to request that specific value. Might not be the cleanest way to do it, but it works.

      Comment

      Working...