Two drop down boxes in php and mysql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghjk
    Contributor
    • Jan 2008
    • 250

    Two drop down boxes in php and mysql

    In my application I have two drop down boxes. 2nd drop down box should filled according to the selected value on the 1st drop down box. But My 2nd drop down box not update.This is my code

    Code:
    <script type="text/javascript">
    	function showSelected(val){
    		document.getElementById('selectedResult').innerHTML = "The selected number is - " + val;
    	}
    	function show(val){
    		document.getElementById('model').innerHTML = "The selected number is - " + val;
    	}
    </script>
    <td>Make :</td> 
    <td>
    
    <select name="make"  class="normalTxt" onChange='showSelected(this.value)' >
    <?php	$mysql_result1 = mysql_query("SELECT DISTINCT vehicleMake FROM  vehicles");
    while($row = mysql_fetch_array($mysql_result1)){
    foreach( $row AS $key => $val )
    $Make = stripslashes( $val );
    						
    ?>
    <option  value=<?php  echo  "'$Make'" ?> ><?php echo "$Make&nbsp;&nbsp;&nbsp;"?>
     <?php 
    	}	
    ?>
     </option>
    </select>
     <?php
    
    ?>
    </td>
    <div id='selectedResult'></div>
    
      <td>Model :</td> 
        <td>
    	
    	
    <select name="vehicleModel" class="defaultBlackText" onChange='show(this.value)'>
    <option value="Select" selected="selected">Select</option>
    <?php
    	
    $qq = mysql_query("SELECT * FROM vehicles WHERE vehicleMake= '".$Make."' ");
    while($row = mysql_fetch_array($qq)){
    foreach( $row AS $key => $val ){
    $$key = stripslashes( $val );
    }?>
    <option> <?php 
    echo "$vehicleModel"; 
    ?> 
    </option>
    <?php }
    //}?>
    
    </select>
    </td>
    <div id='model'></div>
    Please help me..
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    PHP does not run on the client side. Either you have to submit the page to itself and pass the value that was selected or you send an HTTP request to a different PHP page that will return the values. The first option is easier but forces a refresh of the entire page every time the user selects a make. The second option requires more javascript and an additional PHP page but is more fluid.

    Comment

    Working...