TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Changing quanity/price (http://www.talkphp.com/absolute-beginners/5825-changing-quanity-price.html)

KingOfTheSouth 03-24-2011 06:12 PM

Changing quanity/price
 
Hi,

I am having some problems I am not the greatest with this type of things I am trying to do. I am looking for an answer and a easy way to learn to do this.

First off I want my customer to be able to change the quantity then when they pick the quantity the price will change automatically. I know there is a paypal way to do this but I want it to be done on my site. I am selling site credits kind of like zynga cash on the facebook games.

Kind of like

<select name="howmany">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>


They will choose one of them options but there are three options to purchase and they are $5 $10 and $15

Now let's say if they choose 5 as the quantity and the $10 option then it updates to $50 and what ever the credit amount updates as well to 5 times the original. If you need more info just ask me.

tony 03-25-2011 12:46 AM

it seems that your best fit is using javascript listening to the SELECT onChange event. I don't know where you want the result to come up so I am going to put it in an input text for this example:
the html
html Code:
<select id="howmany">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>

<select id="price_options">
<option value="5">5</option>
<option value="10">10</option>
<option value="15">15</option>
</select>

<input type="text" id="calc_result" readonly />
the javascript
javascript Code:
document.getElementById("price_options").onchange=function(){
 var qty_menu=document.getElementById("howmany"),
     result=document.getElementById("calc_result"),
     qty=Number(qty_menu.options[qty_menu.selectedIndex].value),
     price=Number(this.options[this.selectedIndex].value);

 result.value = (price * qty) + '';
}

That is untested code, just came up with it. It just shows the gist of the behavior you wanted.

KingOfTheSouth 04-20-2011 11:47 AM

I figured it out. Thanks Tony here is what I did

of course I used the same HTML selection option and just did this

PHP Code:

$howmany = $_POST['howmany'];
$buyfor = $_POST['buyfor'];

<?php
$pack 
mysql_fetch_array(mysql_query("SELECT packprice,packamount FROM $tab[packs] WHERE id='$id';"));
$cost = ($howmany*$pack[packprice]);
$amount = ($howmany*$pack[packamount]);
?>

I know I look stupid for not knowing that but there are still quite a few things I have trouble with when writing PHP


All times are GMT. The time now is 12:32 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0