You are here: Re: Multiple Dynamic Drop Down Population « PHP Programming Language « IT news, forums, messages
Re: Multiple Dynamic Drop Down Population

Posted by Nick DeNardis on 09/10/06 13:44

Personally i think the best way would be ajax, and there is a million
ways to accomplish it in ajax. Here is a really simple bare bones
example. Like i said this is not the only way to do it but it is pretty
straight forward.

Example:
http://developer.apple.com/internet/webcontent/XMLHttpRequestExample/example.html
Tutorial:
http://developer.apple.com/internet/webcontent/xmlhttpreq.html


Jeff Gardner wrote:
> Greetings:
>
> I have a table with 3 pieces of data that I would like to use to
> dynamically populate 3 drop downs using javascript. The fields are
> state, orgname, office. If it's not already obvious, I'd like orgname
> drop down to change when a state is selected and I would like office
> drop down to change when an orgname is selected. I can do this with
> multiple tables but am having difficulty getting it to work when the
> data is in the same table. Below is the code to get state and orgname
> from separate tables(the code reflects one table and is broken in the
> below state). It's the best I can come up with and I can see why it
> doesn't work but I know there must be a way to pull all the pieces from
> a single table. Advice is much appreciated.
>
> <code>
> $list=$_SESSION['list'];
> if(isset($list) and strlen($list) > 0){
> $quer=mysql_query("SELECT DISTINCT orgname,org_id FROM organization
> WHERE state=$list ORDER BY orgname");
> }else{$quer=mysql_query("SELECT DISTINCT orgname FROM organization ORDER
> BY orgname"); }
> $quer2=mysql_query("SELECT DISTINCT state FROM organization ORDER BY
> state");
>
> //first drop down
> echo "<select name='state' onchange=\"reload(this.form)\"><option
> value='0'>Select one</option>";
> while($state = mysql_fetch_array($quer2)) {
> if($state['org_id']==@$list){echo "<option selected
> value='$state[state]'>$state[state]</option>"."<BR>";}
> else{echo "<option value='$state[state]'>$state[state]</option>";}
> }
> echo "</select>";
>
> //next drop down
> echo "<select name='org'><option value=''>Select one</option>";
> while($org = mysql_fetch_array($quer)) {
> echo "<option value='$org[org_id]'>$org[orgname]</option>";
> }
> echo "</select>";
> </code>
>
>
>
> --
>
> Regards,
>
> Jeff Gardner
> ___________________________
>
> "Contrary to popular belief, Unix is user friendly. It just happens
> to be very selective about who its friends are." --Kyle Hearn

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация