Jump to content

onChange


zang8027

Recommended Posts

If you go to www.clikndine.com/html/findrestaurants.php , You will notice what my problem is. When you select a drop down from the top, the bottom one fills in BUT the top one resets. Im using:

 

<SELECT NAME="stateList" onChange="this.form.submit()">

 

 

Is there some code that will keep the information in the box? The reason I am using onChange is because the bottom dropdown will fill in with different values for different states. So rather than having the user select a state, and hit a submit button, it automatically updates the form.

Link to comment
Share on other sites

Having onsubmit is fine...but first thing you need to do is get rid of the two form declarations you have...there should only be one set of form tags.

 

I am not sure how you are building the dropdown lists though?

If the values come from a database...you would just loop through ( like you do to build the options )...but check it against the selected value

<?php $_POST["stateList"]; ?>

and the current value in the db...if there is a match...you set the "selected" property of the select element (option item).

 

You also need a check around your mysql statement that you call to pull the cities...something like:

<?php if(trim($_POST["stateList"]) != ''){ //make call to db here } ?>

 

 

Link to comment
Share on other sites

cool, i will look at that topic.

 

Also, I have a few tables in a DB. When Pennsylvania (example) is picked, it refreshes the page and sets a variable = to the ID for PA. Then the city drop down does something along the lines of select * from citySmall where stateID = $stateID

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.