Problem retraving full list of subcat

Discussion in 'PHP' started by zed420, Feb 23, 2009.

  1. #1
    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);
    }
    Code (markup):

     
    zed420, Feb 23, 2009 IP
  2. zed420

    zed420 Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    Anyone please ???
     
    zed420, Feb 23, 2009 IP