dependent multiple list menu

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amel86
    New Member
    • Apr 2010
    • 25

    dependent multiple list menu

    Hello,
    I have a problem. I need to do multiple list menu which is populate each other when selected.
    The problem is my code run perfect on my localhost server but when i upload to the server the code seem not too worked. it not update the result.

    For example if i select category A it should list out sub category A that is A1 and A2. But, the result is it list out A1, A2 and A3 even i already remove A3 subcategory. So, for me it not update the result. Please help me how to modify this code so that it can run smoothly on the server.

    Code:
    <script>
    function getXMLHTTP() { //fuction to return the xml http object
    		var xmlhttp=false;	
    		try{
    			xmlhttp=new XMLHttpRequest();
    		}
    		catch(e)	{		
    			try{			
    				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
    			}
    			catch(e){
    				try{
    				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    				}
    				catch(e1){
    					xmlhttp=false;
    				}
    			}
    		}
    		 	
    		return xmlhttp;
    	}
    	function getmodel(strURL) {		
    		
    		var req = getXMLHTTP();
    		
    		if (req) {
    			
    			req.onreadystatechange = function() {
    				if (req.readyState == 4) {
    					// only if "OK"
    					if (req.status == 200) {						
    						document.getElementById('modeldiv').innerHTML=req.responseText;						
    					} else {
    						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
    					}
    				}				
    			}			
    			req.open("GET", strURL, true);
    			req.send(null);
    		}				
    	}
    </script> 
    
    
    <form name="testform" action="insert_product.php" method="post" enctype="multipart/form-data" onsubmit="return checkform(this);"> 
    
    <select name="category" onChange="getmodel('populate.php?category='+this.value)">
            <option value='-1'>Select Category</option>
            <?
            $q=mysql_query("select * from category where main_category_id = '1' ORDER BY category ASC ");
            while($n=mysql_fetch_array($q)){
            echo "<option value=$n[category_id]>$n[category]</option>";
            }
            ?>
            </select>
    
    
    <div id="modeldiv">
            <select name="model">
            <option>Select model</option> 
            </select>
            </div>
    </form>
    
    
    
    //populate.php code
    
    <? $category=$_REQUEST['category'];
    include("db.inc");
    mysql_select_db('lenhoe');
    $query="select * from model where category_id=$category";
    $result=mysql_query($query);
    
    ?>
    <select name="model">
    <option>Select model</option>
    <? while($row=mysql_fetch_array($result)) { ?>
    <option value="<?=$row['model_id']?>"><?=$row['model']?></option>
    <? } ?>
    </select>
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    If your program runs on one machine, but not another, then it's not a problem with your code but with the server and/or configuration differences between the machines.



    Dan

    Comment

    Working...