PDA

View Full Version : 3 radio, 2 checkbox change 1 Input variable



SH77
Mar 21st, 2007, 04:56 AM
I need to pass a hidden variable to paypal thats value changes based on a form like:

<input type="hidden" name="encrypted" value="xxx">

() Red Sweater (radio) default selected
() Green Sweater (radio)
() Blue Sweater (radio)
[] Add a hat (checkbox1) default checked
[] Add socks (checkbox2)

[submit button]

Im pretty sure that html alone can't do this. I know C, and PHP but am having a hard time understanding javascript. How can I change the variable without getting too complicated. Also the form needs to default to something if the client doesnt support javascript.

nikkiH
Mar 21st, 2007, 11:27 PM
What is it exactly you need to send?
Also, why not use PHP so you aren't requiring javascript on the client?

If you need script, the basic syntax is
document.formname.elementname.value

You'd have to attach the script to some sort of event, probably here just do it on submit since the goal is simply to set a hidden field.

<form ... onSubmit="this.elementname.value='whatever'">

It can get more complicated from there, such as calling a function that checks the values of your form elements.

<form ... onSubmit="setVar(this)">

SH77
Mar 22nd, 2007, 06:01 PM
I would like to use PHP. But how can I pass a hidden variable to paypal using PHP thats on my server?

nikkiH
Mar 22nd, 2007, 09:55 PM
I'm a fan of confirmation pages.
Original form can be html or php. Submits to confirm.php.
confirm.php checks inputs and writes a form with all hidden vars (original form values are written there, all the fields can have the same name, just make them hidden and set value to the request.form value) and an action of the paypal page. Only visible control is the submit button. Fields display to user, obviously, as text for them to confirm. Any calculations made may also display, or errors on input, whatever. You then also add the hidden field you wanted to calculate based on the other form values.
When the user clicks the "confirm" button the hidden field was already there, generated by the php.

That make sense?
If you're used to the error checking/form writes being on the same page (a la perl cgi) you can certainly do that instead of using a separate page. I prefer a separate page personally, as it's easier to help prevent accidental double-submit, too.

SH77
Mar 23rd, 2007, 08:34 PM
Paypal has its own confirmation pages. Dont want to make the process too long. I did get this to work using javascript. Anyway heres the code if anyone is interested.

Working Code (http://freedomsforums.com/javascript-form-3-radios-2-checkbox-pass-1-hidden-variable-t151.html)