hallo, i have 3 select boxes. they all are geting data from a database (different relatives tables). i want when i select something from the first select box the other 2 boxes to be filled with different data regarding my selection. i need a hint or some code. how can i implement such task?
I have achieved this through a combination of js and php function reload(form) { var val=form.comp_cat_1.options[form.comp_cat_1.options.selectedIndex].value; //var val2=form.comp_cat_2.options[form.comp_cat_2.options.selectedIndex].value; self.location= location.href+ '&comp_cat_1=' + val; } Code (markup): <select name="comp_cat_1" id="comp_cat_1" onchange="reload(this.form);"> Code (markup):
yes. i ve seen that. but something it is not right here is my code. would u check it? //in head <SCRIPT language=JavaScript> function reload(form) { var val=form.cat.options[form.cat.options.selectedIndex].value; self.location='bathmoi.php?cat=' + val ; }</script> Code (markup): in boby after succesfull database connection @$cat=$_GET['cat']; @$cat=$HTTP_GET_VARS['cat']; ///////// Getting the data from Mysql table for first list box////////// $quer2=mysql_query("SELECT DISTINCT eidikotita, id_eidikotitas FROM eidikotita order by eidikotita"); ///////////// End of query for first list box//////////// /// for second drop down list we will check if category is selected else we ////will display all the subcategory if(isset($cat) and strlen($cat) > 0){ $quer=mysql_query("SELECT lastname, firstname, fathersname FROM members where id_eid=$cat order by lastname"); $quer1=mysql_query("SELECT mathima FROM mathimata where id_eid=$cat order by mathima"); }else{$quer=mysql_query("SELECT lastname, firstname, fathersname FROM members order by lastname"); $quer1=mysql_query("SELECT mathima FROM mathimata order by mathima"); } ////////// echo "<form method=post name=f1 action='apousies-ins.php'>"; ////////// Starting of first drop downlist ///////// echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Åéäéêüôçôá</option>"; while($noticia2 = mysql_fetch_array($quer2)) { if($noticia2['id_eidikotitas']==@$cat){echo "<option selected value='$noticia2[id_eidikotitas]'>$noticia2[eidikotita]</option>"."<BR>";} else{echo "<option value='$noticia2[id_eidikotitas]'>$noticia2[eidikotita]</option>";} } echo "</select>"; ////////////////// This will end the first drop down list /////////// ////////// Starting of second drop downlist ///////// echo "<select name='subcat'><option value=''>ÊáôáñôéæüìåÃïò</option>"; while($noticia = mysql_fetch_array($quer)) { echo "<option value='$noticia[lastname], $noticia[firstname], $noticia[fathersname]'>$noticia[lastname], $noticia[firstname], $noticia[fathersname] </option>"; } echo "</select>"; //echo "<input type=submit value=Submit>"; //echo "</form>"; ////third list echo "<select name='subcat1'><option value=''>ÌÜèçìá</option>"; while($noticia = mysql_fetch_array($quer1)) { echo "<option value='$noticia[mathima]'>$noticia[mathima] </option>"; } echo "</select>"; ////////////////// This will end the third drop down list /////////// /// /// /// /// echo "</form>"; Code (markup): the $cat variable remains empty. what did i do wrong?? check it here http://iek-kozan.koz.sch.gr/admin/apousies/apousies.php
You can see code sample here http://codingforums.com/showthread.php?t=137111 Having select boxes change based on other select box option selected.
hi dourvas, i don't know if including javascript is the most efficient way (one of reason being that it's executed on client's side, which is out of your control). as far as i understand your request, you mean something like: http://www.int-league.com/crclub.php (choosing a region after having selected a country (best exemple would be the USA of france), after all fields above are filled) go ahead test it! it' free! if this is the solution you're looking for (the only javascript-part being "onchange=submit()") i'm not sure you'll like the solution! it's done with templates! let me know if you want to know more! as a matter of facts i'm almost exclusively working with templates, since i hate to mix scripting languages within the same file; besides, it's much easier and more flexibel!