I tried posting this in Javascript forum with no bites so i figured maybe php could be used instead. I know absolutly 0 javascript but would like to autopopulate an option box based on a previous options choice. This is what I have so far could any of you please help with this? (would prefer it all to be done in php with no javascript) in the header: <html> <head> <SCRIPT language=JavaScript> function reload(form) { var val=form.series.options[form.series.options.selectedIndex].value; self.location='newquote.php?series=' + val ; } </script> </head> Code (markup): in the body: <form method="post" action="bridgestartnewquote.php"> <table width="750" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="200" align="right">Series: <?php $result = mysql_query("SELECT series FROM series"); print "<select name=series onchange=\"reload(this.form)\"> \n"; print "<option></option>"; while($row = mysql_fetch_assoc($result)) { print "<option value=\"{$row['series']}\">{$row['series']}</option> \n"; } print "</select> \n"; ?> </td> <td width="275" align="right">Name: <input type="text" name="quotename" style="width: 150px"></td> <td width="275" align="right">Model: <?php $result = mysql_query("SELECT model FROM models"); print "<select name=model> \n"; print "<option></option>"; while($row = mysql_fetch_assoc($result)) { print "<option value=\"{$row['model']}\">{$row['model']}</option> \n"; } print "</select> \n"; ?> </td> </tr> <td></td> <td></td> <td align="right"><input type="submit" value="Start Quote"></td> </table> </form> Code (markup): This is obviously a combination of php and javascript .... thank you for any help
You NEED Javascript for that. PHP runs on the server, and cannot modify the page contents once it has outputted the page to the user.
Could you not get the page to submit a query each time an option box is selected, then the next option box is loaded with the result of the last query
Not without submitting the form manually. If you want this to happen automatically when an option is selected, then you need Javascript.
Okay I can use javascript to refresh the page on change but how can I use php to change the dropdown after saving a variable in the url for multiple boxes that will have to change based on each previous choice. Example: choose country from database of countries (this will change the second box if US selected to states) then once a state is selected (this changes the next box to cities) It needs to do this while keeping the previous selections in place. Problem: when US is chosen it refreshes keeping US and gives me the states in the second box. When I choose the state it erases US but keeps the state and gives me the cities option in the third box. I still need US available and showing. This is just an example the page I am working on is much more complex but this scenario would be rather close and I think I can take it from there. Thank you for any help.
I think JS is your best bet here. The way I've always had to do this in the past is to search through the options on each list, and then select according to conditions. There are other solutions floating around on the web, but one I use looks like this: function searchSel(selectedValue, theid) { var op = document.getElementById(theid); for(var i=0;i<op.length;i++) { if(op.value == selectedValue) { op.selected = true; break; } else op[0].selected = true; } } Using this function you pass what you are looking for using 'selectedValue' and you pass the ID of where you are searching using 'theid'. So, if you wanted to select the States item in the your list with an ID of Places, you'd call the function like this: searchSel('States', 'Places'); ...or you could call it based on an onchange() or onclick from a prior list. You'd just need to grab the value of the selected item from the prior list which could be done using: var selectedIndex = document.yourFormName.yourListName.selectedIndex; var selectedValue = document.yourFormName.yourListName.options[selectedIndex].value; I hope this helps and best of luck with it!
visit this "wwwdotsitepointdotcom/forums/showthreaddotphp?t=47900 " it has a lot of useful programming tutorials.. btw.. replace the dot word with the . symbol.