Okay, here's the situation... (my parents went away on a weeks vacation..)
but seriously
My original (working) script is simple in its complexity, its for pricing update on a gaming site
Select game > select server > enter quantity, price updates
here is what i have for that
<!-- broken up to see the separate components -->
<input type="text" name="quantity" onkeyup="javascript:while(isNaN(this.form.quantity.value)){this.form.quantity.value=\'\'}
while(this.form.quantity.value > '.$info['maxsell'].'){
this.form.quantity.value='.$info['maxsell'].';
}
if(('.$info['profit'].'-((this.form.quantity.value/'.$info['sellunit'].')*'.$info['profitdrop'].'))>'.$info['profitlow'].'){
this.form.ppprice.value=((this.form.quantity.value*('.$row['price'].'/'.$info['buyunit'].'))*(('.$info['profit'].'-((this.form.quantity.value/'.$info['sellunit'].')*'.$info['profitdrop'].'))/\'100\')+(this.form.quantity.value*('.$row['price'].'/'.$info['buyunit'].'))).toFixed(2);
return false;
}else{
this.form.ppprice.value=((this.form.quantity.value * ('.$row['price'].'/'.$info['buyunit'].'))*('.$info['profitlow'].'/\'999\') + (this.form.quantity.value*('.$row['price'].'/'.$info['buyunit'].'))).toFixed(2);
return false;
}"/>
I know, instead of doing it in the input field i should have created a function and called it - cleaner, hopefully the fix to this will help me do that
// the strings are as follows
$info['maxsell'] = // highest quantity we will sell (200000 example)
$info['sellunit'] = // what we sell in (sell in quantities of 100 units for example)
$info['buyunit'] = // what we but in (buy by 100's for example)
$row['price'] = // what item costs us (2 dollars per $info['sellunit'] for example)
$info['profit'] = // profit margin for item %
$info['profitlow'] = // lowest acceptable profit margin
// (bulk orders get discounted on sliding scale)
$info['profitdrop'] = // what % profit will drop by $info['sellunit']
// 0.09 per $info['sellunit'] from $info['profit'] until $info['profitlow'] is reached
// dont think i missed any
Okay, so first we check to see its a number, then we check that the number doesn't violate the "maxsell" value
after that, we check the quantity and do the math to ensure it gets the proper discount and displays the price in the field (this.form.ppprice.value) (ppprice = paypal price)
This works fine and dandy for choosing 1 game then going to next page and choosing 1 server, then going to next page to get prices (as there will be only 1 price structure as its 1 single game)
I am trying to condense this form to a single page....
choose game, server, then input quantity, have that quantity update, unfortunately different games, servers will have different prices, profits, even buy/sell quantities
I know i will need to create an array in javascript with the information, then match the math function to the right fields, but i am not that good at javascript (see my hacked function above as evidence)
i have the values in a php array now..
// example, games select box
// "world of warcraft" (this.form.games.value = 17) and
// "world of warcraft - europe" (this.form.games.value = 18)
$buyunit[17] = 100;
$sellunit[17] = 100;
$profit[17] = 37;
$profitlow[17] = 30;
$profitdrop[17] = '.09';
$minsell[17] = 2000;
$maxsell[17] = 200000;
$buyunit[18] = 100;
$sellunit[18] = 100;
$profit[18] = 40; // notice, some change, but some stay the same
$profitlow[18] = 35;
$profitdrop[18] = '.07';
$minsell[18] = 2000;
$maxsell[18] = 200000;
// the price value is server dependant... so we will use the server select box
// small example, dont need the names really, using this.form.server.value = (number from 1-2000 ish)
$price[1] = '1.90';
$price[2] = '1.85';
$price[3] = '1.20';
$price[4] = '1.90';
$price[5] = '2';
$price[6] = '1.90';
$price[7] = '1.40';
$price[8] = '1.90';
$price[999] = '1.70'; // prices change per game, and sometimes per server (harder to get higher price)
So.. using this info, how can i edit my form to do the new math
most likely, as my list is going to span over 2500 lines i should use an external but as its generated from php database call will that be even possible?