Click to See Complete Forum and Search --> : Javascript Paypal Order Form


Gadget
07-27-2003, 12:19 AM
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 :\
The Html
<!--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">

The Javascript Function
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';
}
}
}

Thuy
07-27-2003, 01:14 AM
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

Gadget
07-27-2003, 09:53 AM
Originally posted by Thuy
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
I tried that :\ It didnt work all it did was make my values negative :/

Thuy
07-27-2003, 01:01 PM
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';
}
//...
}

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

Gadget
07-27-2003, 01:04 PM
Originally posted by Thuy 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]
LOL, I am trying to change the value of myForm.a3 it has to change.

Thuy
07-27-2003, 01:15 PM
I tried that :\ It didnt work all it did was make my values negative :/

What did you try before to get negative result?

Thuy

Gadget
07-27-2003, 01:32 PM
Using variables. :\ Thats why i put hidden inputs in.

Thuy
07-27-2003, 01:49 PM
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