TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-24-2011, 06:12 PM   #1 (permalink)
The Acquainted
 
KingOfTheSouth's Avatar
 
Join Date: Oct 2008
Location: Cincinnati
Posts: 151
Thanks: 14
KingOfTheSouth is on a distinguished road
Default 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.
KingOfTheSouth is offline  
Reply With Quote
Old 03-25-2011, 12:46 AM   #2 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

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.
tony is offline  
Reply With Quote
The Following User Says Thank You to tony For This Useful Post:
KingOfTheSouth (04-20-2011)
Old 04-20-2011, 11:47 AM   #3 (permalink)
The Acquainted
 
KingOfTheSouth's Avatar
 
Join Date: Oct 2008
Location: Cincinnati
Posts: 151
Thanks: 14
KingOfTheSouth is on a distinguished road
Default

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
KingOfTheSouth is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing &eacute; into html entities without touching the html elements ? Peuplarchie General 1 11-10-2009 12:12 PM
Changing Array Key Values ReSpawN Absolute Beginners 7 05-27-2008 09:31 PM
Changing imagesize while uploading. lesP Advanced PHP Programming 3 04-10-2008 07:00 PM


All times are GMT. The time now is 01:30 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design