Hey guys! Been a lurker here for quite some time, as I'm good at learning without asking questions. Today though, I am stumped. I know it's possible, and probably with just a few lines of code, but I just can't quite figure this one out. Here's what I need to do.. I have three javascript variables that I need to populate my PayPal forms with, to making their shopping experience easier. While not the best solution, and hopefully not a permanent one, I have to settle for this script because I can't even begin to comprehend what a custom, field-updating country drop-down menu with exchange rate lookup would be like to code, and I just don't have that kind of brain power yet! In the mean time, I have these three variables.. which I get via these scripts (the second script is just an example of how to use the variables in their own right).. <script type="text/javascript" src="http://gd.geobytes.com/gd?&variables=GeobytesCountry,GeobytesIso2,GeobytesCurrencyCode"></script> <script type="text/javascript">document.write(sGeobytesCountry+","+sGeobytesIso2+","+sGeobytesCurrencyCode);</script> Code (markup): Okay, so what I'd like to do is populate the three values marked with a "__" here.. <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" name="pp"> <input type="image" src="images/atc.png" name="submit" alt=""> <input type="hidden" name="add" value="1"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="business" value="john@doe.com"> <input type="hidden" name="item_name" value="Product"> <input type="hidden" name="amount" value="__"> <input type="hidden" name="no_shipping" value="2"> <input type="hidden" name="currency_code" value="__"> <input type="hidden" name="lc" value="__"> <input type="hidden" name="bn" value="PP-ShopCartBF"> </form> Code (markup): The last two variables are pretty straightforward, where the "currency_code" value refers to the (sGeobytesCurrencyCode) variable, and the "lc" value refers to the (sGeobytesIso2) variable. The "amount" value is where it unfortunately gets ugly though. I need it to be derived from the (sGeobytesCurrencyCode) variable and follow some conditioning, like: if (sGeobytesCurrencyCode) is USD / then "amount" value is $37 else if (sGeobytesCurrencyCode) is CAD / then "amount" value is $36 else if (sGeobytesCurrencyCode) is EUR / then "amount" value is $24 else if (sGeobytesCurrencyCode) is GBP / then "amount" value is $19 else if (sGeobytesCurrencyCode) is AUD / then "amount" value is $40 else if (sGeobytesCurrencyCode) is XXX / then "amount" value is $37 USD ..all remaining currencies are converted to USD upon checkout.. I just need that last rule as a catch-all. PayPal fortunately ignores any currency code it does not support or recognize. Also, now that I think about it, it would be nice to have each currency code dynamically load the appropriate image -- to show as the add-to-cart button. I was thinking something like: <input type="image" src="images/atc__.png" name="submit" alt=""> where "__" refers to the (sGeobytesCurrencyCode) variable. Code (markup): ---------------------------------- So what kind of script could I use to perform this kind of action with? I hope it's a simple one! Lemme know if there's still not enough information to go off of though, kay. ---------------------------------- Well thank you very much for reading this lengthy post, and I look forward to learning a thing or two from you guys today! Hopefully someday I can learn enough to be in your position, and return the favor to some other newbie. Sincerely, William
Just figured it all out.. function amount(countryCode) { var price = { 'USD': 37, 'CAD': 36, ... 'AUD': 40 }; // if no countryCode has been defined, return as a default the USD value return price[countryCode] || price['USD']; } document.getElementById('currencyImage').src = 'atc' + sGeobytesCurrencyCode + '.png'; Code (markup): Until next time! -Will