#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0

    I got a form where you can fill in some details over you're self (name, address, state, city).
    There is a listbox where you can choose a state. When you select a state the page is loaded again and will fill another listbox with all the city's of the chosen state.

    The problem is that when I choose a state (and the page reloads) the other values are gone (the page doesn't send anything).
    I use JavaScript (onChange) to reload the page (PHP) with the city's of the state.

    Does anyone know how I can fix the problem that when the page reloads the values will go to the new screen?
  2. #2
  3. Wiking
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Sep 2000
    Location
    Sweden
    Posts
    3,608
    Rep Power
    27
    Have you tried with setting value=$name like this?
    <input type=text name='name' value=<? echo "$name";?>>

    When u first load the form, value is not set, but when u reload the filled form with JS, the value will be remembered.

    /NoXcuz
  4. #3
  5. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    9
    Rep Power
    0
    I'd be very interested if NoXcus's answer solves this problem, because I can see why it is frustrating. If you reload the page when you change the State box, the form is never submitted, so the values are never set (I think). I haven't tried what NoXcus said, though, so if it works, I'll be very glad.

    Dogg
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0
    The answer of NoXcuz didn't help :-(
    What Dogg says is correct, the form isn't submitted so the values are not set.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 1999
    Posts
    114
    Rep Power
    16
    I wouldn't do this myself, because I generally try to avoid using client-side JavaScript in my applications, but:

    You can put a call to
    form.submit();
    in your select element's onChange function.

    Then you can have your PHP code handle the rest.

    -- Christopher

  10. #6
  11. Wiking
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Sep 2000
    Location
    Sweden
    Posts
    3,608
    Rep Power
    27
    Dogg & scollo - you're both right. I just realized that one shouldn't try thinking on a friday night while drinking whisky...

    I just think I've seen this before but I can't recall where and how right now.



    cheers
    /NoXcuz
  12. #7
  13. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    9
    Rep Power
    0
    But if you submit the form, what happens when you enter the city and you REALLY want to submit the form. How do you solve that problem?

    I suppose that you could have a hidden form feild or something like that to tell you hoe to deal with the form.

    I have some other idea, but I'm not a big fan of them:

    - Do something like mapquest where the visitor types the city, and if it doesn't match a supported city (after the submit), generate a list to chose from.

    - Pre-load the city data for each state so that you don't have to reload the page after selecting the state. (I'm not sure how exactly this would work, and it would mean loading a lot of excess data.)

    Needless to say, both of these ideas are far from perfect, but hopefully they will get the ball moving. Actually, I hope that the JavaScript form.submit() works and this problem is soved. Please let us know if it does work!

    Dogg
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0
    Pre-loading is not a good idea because there are 6045 city's in my database...
    So that will be very slow
    I will try the form.submit() but I'm not good in JavaScript.. well I will see.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Location
    Alkmaar, The Netherlands
    Posts
    123
    Rep Power
    15
    On your page use two forms. One is totally hidden. Whenever a user fills in one of the form-fields a corresponding (hidden) field in the other form is set to the same value. Then when a user selects a state submit the hidden form. You can use those values to set the visible form.


    <FORM NAME="Form1" ACTION="thispage.php">
    <INPUT TYPE="HIDDEN" NAME="Field1">
    </FORM>

    <FORM NAME="Form2" ACTION="submitpae.php">
    <INPUT TYPE="TEXT" NAME="Field2" VALUE="<% echo $Field1; %>" onChange="document.Form1.Field1.value=this.value;">
    <SELECT NAME="State" onChange="document.Form1.State.value=this.value;document.Form1.submit;">
    <OPTION NAME="Bladiebla" VALUE="BlaBla">
    </SELECT>
    <INPUT TYPE="SUBMIT" VALUE="Submit">
    </FORM>

    ------------------
    Good luck,
    Bas

    ------------------
    E-mail me at: b.vandermeijden@pecoma.nl

    [This message has been edited by MeijdenB (edited November 06, 2000).]
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by MeijdenB:
    On your page use two forms. One is totally hidden. Whenever a user fills in one of the form-fields a corresponding (hidden) field in the other form is set to the same value. Then when a user selects a state submit the hidden form. You can use those values to set the visible form.


    <FORM NAME="Form1" ACTION="thispage.php">
    <INPUT TYPE="HIDDEN" NAME="Field1">
    </FORM>

    <FORM NAME="Form2" ACTION="submitpae.php">
    <INPUT TYPE="TEXT" NAME="Field2" VALUE="<% echo $Field1; %>" onChange="document.Form1.Field1.value=this.value;">
    <SELECT NAME="State" onChange="document.Form1.State.value=this.value;document.Form1.submit;">
    <OPTION NAME="Bladiebla" VALUE="BlaBla">
    </SELECT>
    <INPUT TYPE="SUBMIT" VALUE="Submit">
    </FORM>

    [/quote]

    ----------------------------------------------

    Thanx MeijdenB!
    The answer you gave did it!

    Only it works well in IE but not in Netscape. So I have changed this line:
    <SELECT NAME="State" onChange="document.Form1.State.value=this.value;document.Form1.submit;">

    To:
    <SELECT NAME="State" onChange="document.Form1.State.value=document.Form2.State.options[selectedIndex].value;document.Form1.submit;">

    Now it work good in IE and Netscape!

    To all who has helped me: THANKS!
    Now I'm happy again

IMN logo majestic logo threadwatch logo seochat tools logo