/    Sign up×
Community /Pin to ProfileBookmark

Javascript Paypal Order Form

Ok, I am trying to make a Custom Paypal order form with javascripting to eliminate the need for multiple orderforms. I have made the order form and so far it works except for one part. I have a drop down box that has the values ” ” “0” “2” “3” “4” for nameserver choice. upon clicking the box if you select 2 it adds $5.00 to the total, 3 adds $7.00 and 4 adds $10.00. That part works if you only select it once. If you select it again, it adds the value again. I am trying to figure out a way to reverse the original total then add the new total. I have tried several different methods (variables, hidden inputs) right now i have found that hidden inputs are working better for me but now i need to figure out how to do loops and gotos inside the actual function, i tried goTo() but that didnt work. I am going to copy the function that the dropdown uses and the code for the dropdown and all hidden values it works with. If anyone knows anything that might help me could you please offer it :

[QUOTE]

[B]The Html[/B]
<!–webbot bot=”Validation” s-display-name=”Nameservers” b-value-required=”TRUE” –><select onClick=”nsSet(this)” size=”1″ name=”os3″ id=”fp13″>
<option value=”-“>
<option value=”0″>0
<option value=”2″ >2
<option value=”3″ >3
<option value=”4″ >4</select>
<input type=”hidden” name=”nsset” value=”false”>
<input type=”hidden” name=”nsvalue” value=””>
<input type=”hidden” name=”a3″ value=”565.00″>
<input type=”hidden” name=”p3″ value=”22″>
<input type=”hidden” name=”t3″ value=”D”>
<input type=”hidden” name=”a1″ value=”565.00″>
<input type=”hidden” name=”p1″ value=”22″>
<input type=”hidden” name=”t1″ value=”D”>

[/QUOTE]
[QUOTE]

[B]The Javascript Function[/B]
function nsSet(os3Field) {
if (document.myForm.nsset.value == “true”) {
if (document.myForm.nsvalue.value == “2”) {
document.myForm.a3.value=Math.floor(eval(document.myForm.a3.value)-5);
document.myForm.a1.value=Math.floor(eval(document.myForm.a3.value)-5);
document.myForm.price.value=’$’+document.myForm.a3.value;
document.myForm.total.value=’$’+document.myForm.a1.value;
document.myForm.nsset.value=’false’;
}
if (document.myForm.nsvalue.value == “3”) {
document.myForm.a3.value=Math.floor(eval(document.myForm.a3.value)-7);
document.myForm.a1.value=Math.floor(eval(document.myForm.a3.value)-7);
document.myForm.price.value=’$’+document.myForm.a3.value;
document.myForm.total.value=’$’+document.myForm.a1.value;
document.myForm.nsset.value=’false’;
}
if (document.myForm.nsvalue.value == “4”) {
document.myForm.a3.value=Math.floor(eval(document.myForm.a3.value)-10);
document.myForm.a1.value=Math.floor(eval(document.myForm.a3.value)-10);
document.myForm.price.value=’$’+document.myForm.a3.value;
document.myForm.total.value=’$’+document.myForm.a1.value;
document.myForm.nsset.value=’false’;
}
}
if (document.myForm.nsset.value == “false”) {
if (os3Field.value == “0”) {
document.myForm.nsprice.value=’$0.00′;
document.myForm.nsset.value=’true’;
document.myForm.nsvalue.value=’0′;
}
if (os3Field.value == “2”) {
var nsprices = “5”;
document.myForm.a3.value=Math.floor(eval(document.myForm.a3.value)+eval(nsprices))+’.00′;
document.myForm.a1.value=Math.floor(eval(document.myForm.a1.value)+eval(nsprices))+’.00′;
document.myForm.nsprice.value=’$5.00′;
document.myForm.price.value=’$’+document.myForm.a3.value;
document.myForm.total.value=’$’+document.myForm.a1.value;
document.myForm.nsset.value=’true’;
document.myForm.nsvalue.value=’3′;
}
if (os3Field.value == “3”) {
var nsprices = “7”;
document.myForm.a3.value=Math.floor(eval(document.myForm.a3.value)+eval(nsprices))+’.50′;
document.myForm.a1.value=Math.floor(eval(document.myForm.a1.value)+eval(nsprices))+’.50′;
document.myForm.nsprice.value=’$7.00′;
document.myForm.price.value=’$’+document.myForm.a3.value;
document.myForm.total.value=’$’+document.myForm.a1.value;
document.myForm.nsset.value=’true’;
document.myForm.nsvalue.value=’3′;
}
if (os3Field.value == 4) {
var nsprices = “10”
document.myForm.a3.value=Math.floor(eval(document.myForm.a3.value)+eval(nsprices))+’.00′;
document.myForm.a1.value=Math.floor(eval(document.myForm.a1.value)+eval(nsprices))+’.00′;
document.myForm.nsprice.value=’$10.00′;
document.myForm.price.value=’$’+document.myForm.a3.value;
document.myForm.total.value=’$’+document.myForm.a1.value;
document.myForm.nsset.value=’true’;
document.myForm.nsvalue.value=’4′;
}
}
}

[/QUOTE]

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@ThuyJul 27.2003 — Hi,

You should save the original values in some global variables, and every time user choose different selection, the function nsSet(this) should use the originals to do the math with the selection.

Thuy
Copy linkTweet thisAlerts:
@GadgetauthorJul 27.2003 — [i]Originally posted by Thuy [/i]

[B]Hi,



You should save the original values in some global variables, and every time user choose different selection, the function nsSet(this) should use the originals to do the math with the selection.



Thuy [/B]
[/QUOTE]

I tried that : It didnt work all it did was make my values negative :/
Copy linkTweet thisAlerts:
@ThuyJul 27.2003 — function nsSet(os3Field) {

if (document.myForm.nsset.value == "true") {

if (document.myForm.nsvalue.value == "2") {

document.myForm.a3.value=Math.floor(eval(document.myForm.a3.value)-5);

document.myForm.a1.value=Math.floor(eval(document.myForm.a3.value)-5);

document.myForm.price.value='$'+document.myForm.a3.value;

document.myForm.total.value='$'+document.myForm.a1.value;

document.myForm.nsset.value='false';

}

//...

}[/QUOTE]


I would suggest you to try these modifications:

1/ Declare new variable in the function nsSet to hold the result of the calculation.

For example, var My_a3=Math.floor(eval(document.myForm.a3.value)-5);

This way, you still keep the original value of the myform.a3

2/ In the select tab, try to use onChange instead of onClick.

Wish you luck,

Thuy
Copy linkTweet thisAlerts:
@GadgetauthorJul 27.2003 — [i]Originally posted by Thuy [/i]For example, var My_a3=Math.floor(eval(document.myForm.a3.value)-5);

This way, you still keep the original value of the myform.a3 [/B][/QUOTE]

LOL, I am trying to change the value of myForm.a3 it has to change.
Copy linkTweet thisAlerts:
@ThuyJul 27.2003 — I tried that : It didnt work all it did was make my values negative :/[/QUOTE]

What did you try before to get negative result?

Thuy
Copy linkTweet thisAlerts:
@GadgetauthorJul 27.2003 — Using variables. : Thats why i put hidden inputs in.
Copy linkTweet thisAlerts:
@ThuyJul 27.2003 — I thought using another hidden input to hold the original value should work fine in this case. I don't understand why you get the negative value? It doesn't make sense to me.

Thuy
×

Success!

Help @Gadget 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...