View Full Version : loading <select> options based on previous <select> choice

07-15-2004, 10:13 PM

Hi, I am quite rusty with javascript as I dont use it that often so i need a little guidance!!

I need to load the contents of a drop down menu but the contents are to be dependant on the selection of a previous drop down menu. It is of the form country-region-town. The values are stored in a database each with associated id's and foreign keys but i thought it was best to retrieve all items and then use javascript to load the appropriate contents, its just that I dont know how!!

I thought i'd ask as i imagine its something that developers come across every now and then. If ive got the wrong end of the stick and it is a php question let me know and I will post tin the other forum.


Vincent Puglia
07-15-2004, 10:22 PM

see the cascading selects scripts/explanations at : http://members.aol.com/grassblad

also, dynamicdrive has one or two scripts w/o explanation


07-16-2004, 12:15 AM
thanks, thats a big help but im retrieving all my data from a mysql database and hence my arrays will be php arrays rather than javascript arrays, im a bit stuck on how to approach this!

Vincent Puglia
07-16-2004, 12:20 AM
$connect = odbc_connect($db, $user, $pass) or die ($error);
$query = "SELECT * FROM TABLE";
$result = odbc_exec($connect, $query);

$arrDef[] = '"'.$result.'"';


$strJsArr = implode(',', $arrDef);

echo 'var arr = ['.$strJsArr."]\n";