View Full Version : onClick.. passing variables

07-12-2005, 03:13 PM

I have a form.. This is what it looks like:

<form method="post" name="tcreate">
Name: <input type="text" name="uname"><br/>
Age: <select name="age" onChange="if(this.options[this.selectedIndex].value) window.location=\'?age=\'+this.options[this.selectedIndex].value;">
<option value="Under 13">Under 13</option>
<option value="13 - 17">13 - 17</option>
<option value="18 and over">18 and over</option>
<input type="submit" name="submit" value="Submit">

Now... when the person changes thier age... the page basically reloads, and something appears under the form according to the answer they selected. I have that down no problem. However, if the person enters in their name and then changes the age, the page reloads and they have to re-enter their name again.

Not a big deal for this form.. however this is just a small snippet of the form. There are over 20 questions, and I want these values to stay put.

How would I go about this?

Thanks in advance! :thumbsup:


07-12-2005, 03:15 PM
You have to save the values and re-write them to the form (server-side, usually).
Which means the form has to submit so you get all the values. You can't change the location like that unless you also write ALL the form values as a querystring.
Instead of using window.location, have the onchange submit the form and go from there.

07-12-2005, 03:30 PM
Easy enough.. worked wonders as I'm using PHP to recall selected values.

Thanks! :thumbsup: