Re: Drop-down menu selection

From: Date: Wed, 21 Feb 2001 01:29:21 +0000
Subject: Re: Drop-down menu selection
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-6808@lists.php.net to get a copy of this message
You need mix JavaScript and PHP. Write an "OnChange" event handler for the "campus" selection list and fill up the "buildings" drop-down menu in two ways: 1) If the amount of data is not very large you can get all data needed to run the "application" client side, load the data into JavaScript arrays and refresh the select boxes using JavaScript scripts. Otherwise you must reload the page and process the values posted by the form. 2) Reload the same page (window.location="self.php?campus=value") and run your php script to fill up the "buildings" drop-down menu. HTH. Jayme. -----Mensagem Original----- De: Julio Cuz, Jr. <jcuz@rccd.cc.ca.us> Para: <php-db@lists.php.net> Enviada em: terça-feira, 20 de fevereiro de 2001 21:44 Assunto: [PHP-DB] Drop-down menu selection > Hi-- > > I hope all of you are having a great long weekend! > > Let's say I have four (4) tables: > > - "campus" that holds all my campuses' names (only 3), > - "building_campus1" that holds all buildings for 'campus1', > - "building_campus2" that holds all buildings for 'campus2', > - "building_campus3" that holds all buildings for 'campus3'. > > If the user selects "campus 1" from a drop-menu, how can I select > "buildings for campus 1" on a second drop-down menu? In other words, how > do I select the corresponding "building's table" when any "campus" is selected? > > Thanks! > > P.S. I have tried the 'onChange' command, but I guess I got the syntax wrong: > > ================================================================= > // $campus: > <?php > echo("<SELECT onChange='building.value = building.this.value' NAME='campus'>"); > $cmlist = @pg_exec($db, "SELECT * FROM \"Campus\"") or > die(include("../sqlerror.inc")); > $i = 0; > $x = pg_numrows($cmlist); > while ($i < $x): > $clist = pg_fetch_array($cmlist,$i); > echo "<OPTION > > VALUE='".$clist["Campus"]."'>".$clist["Campus"]."</OPTION>"; > $i++; > endwhile; > echo("</SELECT>"); > ?> > > $building: > <?php > echo("<SELECT NAME='building'>"); > $cmlist = @pg_exec($db, "SELECT * FROM building_$campus") or > die(include("../sqlerror.inc")); > $i = 0; > $x = pg_numrows($cmlist); > while ($i < $x): > $clist = pg_fetch_array($cmlist,$i); > echo "<OPTION > > VALUE='".$clist["Building"]."'>".$clist["Building"]."</OPTION>"; > $i++; > endwhile; > echo("</SELECT>"); > ?> > ================================================================= > > Julio Cuz, Jr. > Riverside Community College > jcuz@rccd.cc.ca.us

« previous php.db (#6808) next »