SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: Help with pricing module.
-
Aug 17, 2006, 11:23 #1
- Join Date
- Mar 2005
- Location
- Many places.
- Posts
- 53
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Help with pricing module.
Hello,
I've been posting related questions but have not had much luck, so I figured I'd just put the whole problem out there.
I have 2 separate prices for each product in a database: 'New' and 'Like New'. These products also have accessories which can be added to the products' package each with 2 prices. I want to change the pricing for all of the accessories by clicking on a radio button selection. So, without knowing javascript at all, I am trying to make it so that the <input name="Price[]" value="this should change"> tags and the text of the Price change when you select the 'Like New' radio button and back when you select the 'New' radio button.
My strategy this far has been to pull all of the prices into an array like this:
Code:nPrice = new Array ("106.99" , "86.99" , "115.99" , "319.99" , "") rPrice = new Array ("89.99" , "74.99" , "102.99" , "239.99" , "")
Code:function setCheckedValue(radioObj, newValue) { if(!radioObj) return; var radioLength = radioObj.length; if(radioLength == undefined) { radioObj.checked = (radioObj.value == newValue.toString()); return; } for(var i = 0; i < radioLength; i++) { radioObj[i].checked = false; if(radioObj[i].value == newValue.toString()) { radioObj[i].checked = true; } } }
Code:function GetThePrices(){ var priceLength = document.choices.Price.length; if (radioObj[0].checked == true){ for(var i = 0; i < priceLength; i++) { document.choices.Price[i].value = nPrice[i]; return document.choices.Price[i].value; } if (radioObj[1].checked == true){ for(var i = 0; i < priceLength; i++) { document.choices.Price[i].value = rPrice[i]; return document.choices.Price[i].value; } }
Code:if (document.choices.New[0].checked == true) { var Price = nPrice[$i]; } if (document.choices.New[1].checked == true) { var Price = rPrice[$i]; } document.write(Price)
Please help!!!!!
Thanks,
Colin
-
Aug 18, 2006, 00:20 #2
- Join Date
- Mar 2004
- Posts
- 1,647
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
u have to trigger it with some function call
regards
-
Aug 18, 2006, 07:38 #3
- Join Date
- Mar 2005
- Location
- Many places.
- Posts
- 53
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Alright, it was easier than I was making it out to be.
I just made the radio buttons do this: onchange = "GetPrices();".
Then the I used PHP (
$i=0;
$products_query = ( "SELECT THE SAME AS WHEN YOU ACTUALLY CALL THE PRODUCTS");
while($result = mysql_fetch_array($products_query) {
echo "DoIt$i();";
$i++;
}
)
in the GetPrices function to create a switch of numbered function calls (i.e. DoIt0 (); DoIt1();, etc.) corresponding to the number of products.
Then for each product $i there was the function (function DoIt0 (), function DoIt1(), etc.) that detected which radio button is checked and set whatever variables I needed passed on (
if (document.choices.New[0].checked == true) {
var addPr = $price;
var addStat = '$nstatus';
}
)
The values and text were then set using:
document.getElementById("Prices0", "Prices1", etc.).innerHTML (to display text you can't use document.write) and
document.getElementById("Status0", "Status1", etc.).value.
etc.
This changes the values and text for all products when different radio buttons are checked.
Hopefully, this will help anybody with the same problem.
Thanks,
Colin
Bookmarks