/    Sign up×
Community /Pin to ProfileBookmark

I need to populate a form based on automatically detected geographic variables..

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 form 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 [i]begin[/i] 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)..

[code]
<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]

Okay, so what I’d like to do is populate the three values marked with a “__” here..

[code]
<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=”[email protected]”>
<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]

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:

[code]
<input type=”image” src=”images/atc__.png” name=”submit” alt=””>

where “__” refers to the (sGeobytesIso2) variable.
[/code]


———————————-

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

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @zoinbergs spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.22,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...