zed420 Posted February 23, 2009 Share Posted February 23, 2009 Hi All I'm trying to populate two dropdown box's, one is Category and by selecting one of them the second dropdown box is populated with it's Subcat, this code below works bit strangely it only gives me ONE Subcategory(client_site) can anyone please tell me why only one??? I've got about 10 site to each client. thanks zed echo " function fillCategory(){ // this function is used to fill the category list on load "; $q1=mysql_query("select client_id,client_name from client"); echo mysql_error(); while($nt1=mysql_fetch_array($q1)){ echo "addOption(document.emp_rec.cl_id, '$nt1[client_id]','$nt1[client_name]');"; }// end of while ?> } // end of JS function function SelectSite(){ removeAllOptions(document.emp_rec.site_id); addOption(document.emp_rec.site_id, "", "Site Name", ""); <? $q2=mysql_query("select site_id from client_site"); while($nt2=mysql_fetch_array($q2)){ echo "if(document.emp_rec.cl_id.value == '$nt2[site_id]'){"; $q3=mysql_query("select site_id,site_name from client_site where site_id='$nt2[site_id]'"); while($nt3=mysql_fetch_array($q3)){ echo "addOption(document.emp_rec.site_id,'$nt3[site_id]','$nt3[site_name]');"; } // end of while loop echo "}"; // end of JS if condition } ?> } function removeAllOptions(selectbox) { var i; for(i=selectbox.options.length-1;i>=0;i--) { selectbox.remove(i); } } function addOption(selectbox, value, text) { var optn = document.createElement("OPTION"); optn.value = value; optn.text = text; selectbox.options.add(optn); } Link to comment https://forums.phpfreaks.com/topic/146502-problem-retrieving-full-list-of-subcat/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.