Page 1 of 1

Add Freight to cart total

Posted: Tue Dec 21, 2004 2:30 pm
by bob_the _builder
Hi,

At the moment it has a java script that updates the qty on click .. The java script is:

Code: Select all

<script language="JavaScript">
  
  	function UpdateQty(item)
  	&#123;
    itemId = item.name;
    newQty = item.options&#1111;item.selectedIndex].text;
    
    document.location.href = 'cart.php?action=update_item&id='+itemId+'&qty='+newQty;
  	&#125;
  
  </script>
The list/menu is made up of:

Code: Select all

<select name="<?php echo $row&#1111;"itemId"]; ?>" onChange="UpdateQty(this)">
            <?php
        
        	for($i = 1; $i <= 20; $i++)
        	&#123;
          echo "<option ";
          if($row&#1111;"qty"] == $i)
          &#123;
          	echo " SELECTED ";
          &#125;
          echo ">" . $i . "</option>";
        	&#125;
        ?>
          </select>
The price is displayed as:

Code: Select all

<?php echo number_format($totalCost, 2, ".", ","); ?>
I have been unable to have the same function to add the freight to the total as well .. using list/menu:

Code: Select all

<select name="freight">
<option>Freight</option>
<option value="8.00">North</option>
<option value="15.00">South</option>
</select>
Any ideas on what I need to do to acheive this?


Cheers

Posted: Tue Dec 21, 2004 2:58 pm
by rehfeld

Code: Select all

<?php
if (isset($_GET['freight'])) {
    $freight_cost = $_GET['frieght'];
    // now add it to the total
}
?>
javascript can be nice and all.... but what happens if your customer doesnt have it turned on? you just lose thier business? you might wanna make sure your shopping cart doesnt rely upon javascript. javascript should be used to enhance it, but should not be required.

Posted: Tue Dec 21, 2004 3:16 pm
by bob_the _builder
Hey,

The javascript allows the total price to be updated on click .. the method you have posted can this acheive the same thing?

Can you help me out a little more ..

But I am planning on adding more prices to the freight charges .. not just the 2 as posted above

Regards


Bob

Posted: Tue Dec 21, 2004 4:49 pm
by rehfeld
no it cant. i posted php, which is serverside.
if you want it submitted onclick youll need to use javascript to submit the form(like your doing w/ the items)