Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts

    onClick.. passing variables

    Hiya...

    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>
    </select><br/>
    <input type="submit" name="submit" value="Submit">
    </form>

    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!

    Taylor.

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts
    Easy enough.. worked wonders as I'm using PHP to recall selected values.

    Thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •