superjumper — 2011-09-04T12:16:49-04:00 — #1
I need a very simple for. Three of the selections pass values to a gateway, and I need the forth to redirect to a special page.
I can't change the name of the form or the gateways won't accept the submission.
c_ankerstjerne — 2011-09-06T04:10:47-04:00 — #2
You're welcome - good luck with your site!
superjumper — 2011-09-05T12:31:38-04:00 — #3
YEAH! Thanks a lot man.
Everything is working. With your help, and the place I copied the original from, I kinda made my first working script.
I don't know if this link will show up, but here it is if you want to see it:
text motif dot com / reports dot html
Thanks a lot Ankerstjerne. That was a life-saver.
c_ankerstjerne — 2011-09-05T10:09:34-04:00 — #4
round(0.025 * 3 * this.value * 100) / 100
You might also encounter problems with numbers being interpreted as strings if you do addition, which is easily solved by dividing by one.
c_ankerstjerne — 2011-09-05T11:58:36-04:00 — #5
Sorry, messed up the example:
Math.round(0.025 * 3 * this.value * 100) / 100
The semicolon doens't make any difference (but it's generally not a bad idea to add it).
superjumper — 2011-09-05T08:28:48-04:00 — #6
It's almost finished.
Run into one small snag, and hope you might be able to help
.03*(2*this.value) - This works fine.
.025*(3*this.value) - This does not!
Does anyone know why JS won't calculate to the third decimal?
It actually does work. If I multiple .025*(5*this.value) and give this.value through the form it multiplies it correctly.
The only problem is I can't pass 37.50000000000001 to paypal!
c_ankerstjerne — 2011-09-05T08:32:43-04:00 — #7
What kind of error are you getting?
superjumper — 2011-09-05T08:37:24-04:00 — #8
I can't pass that on to paypal!
<INPUT type="text" id="Editbox1" style="position:absolute;left:104px;top:6px;width:67px;font-family:Courier;font-size:17px;z-index:3; height: 1em; background-color:#FFFFFF;" size="8" name="quantity1" value="" wrap
val = this.value;
superjumper — 2011-09-05T11:17:11-04:00 — #9
I tacked that on like this and the calculator stopped working:
this.form.amount.value=round(.025* 3 * this.value * 100) / 100;
I'm still pretty new to JS, and I'm not sure what I did wrong in the above.
Did you mean to leave the semi-colon off the end in your example? I have a semi-colon at the end of the line.
c_ankerstjerne — 2011-09-04T14:32:14-04:00 — #10
superjumper — 2011-09-04T14:14:35-04:00 — #11
Sure, here's the code. By gateway I mean the other three options have dollar amount values that are passed on to a payment gateway (paypal, moneybookers, etc). The last option I need to redirect.
<FORM action="https://www.paypal.com/cgi-bin/webscr" method="post"> <INPUT type="hidden" name="cmd" value="_s-xclick"> <INPUT type="hidden" name="hosted_button_id" value="VMMCF6CUGBPAN"> <INPUT type="hidden" name="URL" value="2 Articles">2 Articles<BR> <SELECT name="URL" onChange="window.location.href= this.form.URL.options[this.form.URL.selectedIndex].value"> <OPTION value="250" selected="selected">500 Words</OPTION> <OPTION value="500">750 Words</OPTION> <OPTION value="1000">1000 Words</OPTION> <OPTION value="project.html">1000+ Words</OPTION> </SELECT> <INPUT type="hidden" name="currency_code" value="USD"> <BR> <BR> <INPUT type="image" src="[https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"><IMG alt="" border="0" src="[URL="http://www.sitepoint.com/forums/view-source:https://www.paypalobjects.com/en_US/i/scr/pixel.gif"]https://www.paypalobjects.com/en_US/i/scr/pixel.gif](http://www.sitepoint.com/forums/view-source:https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif)" width="1" height="1"> </FORM>
(I'm not sure why the code window is side scrolling like that.)
What's happening is that the onChange is trying to direct people to page with the number value on the first three options. I would like to form to do absolutely nothing unless two things happen:
1) The forth selection is chosen = redirect
2) The second or third direction is chosen = do nothing: wait for used to press submit button.
I hope I'm being clear. And thanks.
c_ankerstjerne — 2011-09-04T13:20:30-04:00 — #12
What do you mean by 'pass values to a gateway'?
What do you mean by 'redirect to a special page'?
It sounds like you have some code already. Can we see it?
superjumper — 2011-09-04T14:35:32-04:00 — #13
ok. I'll tinker with that. I thought about putting a simple notice below the form telling people is they need more than 1000 words or so to use a custom quote page.
That might be easier. I guess I trying to be suave! :rolleyes: