Add Freight to cart total

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

Add Freight to cart total

Post 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
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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.
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

Post 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
Last edited by bob_the _builder on Tue Dec 21, 2004 5:31 pm, edited 1 time in total.
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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)
Post Reply