zang8027 Posted January 27, 2009 Share Posted January 27, 2009 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. Quote Link to comment Share on other sites More sharing options...
chronister Posted January 27, 2009 Share Posted January 27, 2009 JS is not my strong point, but it looks to me like the page gets refreshed, rather than an AJAX function doing the work. Try using an AJAX function instead of a jump type menu. Nate Quote Link to comment Share on other sites More sharing options...
zang8027 Posted January 27, 2009 Author Share Posted January 27, 2009 ya thats true... never used ajax.. any idea what or where I can find this function I need? Quote Link to comment Share on other sites More sharing options...
sdi126 Posted January 27, 2009 Share Posted January 27, 2009 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 } ?> Quote Link to comment Share on other sites More sharing options...
chronister Posted January 27, 2009 Share Posted January 27, 2009 Here is an AJAX one right here on PHP freaks. Very good too. I used it and modified it to do a few different things. http://www.phpfreaks.com/forums/index.php/topic,155984.0.html Quote Link to comment Share on other sites More sharing options...
zang8027 Posted January 27, 2009 Author Share Posted January 27, 2009 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.