Jump to content

[SOLVED] double drop down from db


sandbudd

Recommended Posts

Hey guys it works when I manually put it in like the first code but will not when I try to pull from database to populate?

 

Here is the index html that works.

 

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<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 getCity(strURL) {      
      
      var req = getXMLHTTP();
      
      if (req) {
         
         req.onreadystatechange = function() {
            if (req.readyState == 4) {
               // only if "OK"
               if (req.status == 200) {                  
                  document.getElementById('citydiv').innerHTML=req.responseText;                  
               } else {
                  alert("There was a problem while using XMLHTTP:\n" + req.statusText);
               }
            }            
         }         
         req.open("GET", strURL, true);
         req.send(null);
      }
            
   }
</script>




</head>

<body>

<form method="post" action="" name="form1">
<table width="60%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="150">Make</td>
    <td  width="150"><select name="country" onChange="getCity('findcity.php?country='+this.value)">
   <option value="" selected>Select Make</option>
   <option value="1">Acura</option>
   <option value="2">Alfa Romeo</option>
   <option value="3">AMC</option>
   <option value="4">Audi</option>
    <option value="5">Bertone</option>
    <option value="6">BMW</option>
    <option value="7">Buick</option>
    <option value="8">Cadillac</option>
    <option value="10">Chevrolet</option>
    <option value="11">Chrysler</option>
    <option value="12">Daewoo</option>
    <option value="13">Daihatsu</option>
    <option value="14">Dodge</option>
    <option value="15">Eagle</option>
    <option value="16">Ford</option>
    <option value="17">Geo</option>
    <option value="18">GMC</option>
    <option value="19">Honda</option>
    <option value="20">Hummer</option>
    <option value="21">Hyundai</option>
    <option value="22">Infiniti</option>
    <option value="23">Isuzu</option>
    <option value="24">Jaguar</option>
    <option value="25">Jeep</option>
    <option value="26">Kia</option>
    <option value="27">Land Rover</option>
    <option value="28">Lexus</option>
    <option value="29">Lincoln</option>
    <option value="30">Mazda</option>
    <option value="31">Mercedes-Benz</option>
    <option value="32">Mercury</option>
    <option value="33">Merkur</option>
    <option value="34">MINI</option>
    <option value="35">Mitsubishi</option>
    <option value="36">Nissan</option>
    <option value="37">Oldsmobile</option>
    <option value="38">Peugeot</option>
    <option value="39">Pininfarina</option>
    <option value="40">Plymouth</option>
    <option value="41">Pontiac</option>
    <option value="42">Porsche</option>
    <option value="43">Renault</option>
    <option value="44">Saab</option>
    <option value="45">Saturn</option>
    <option value="46">Sterling</option>
    <option value="47">Subaru</option>
    <option value="48">Suzuki</option>
    <option value="49">Toyota</option>
    <option value="50">Volkswagen</option>
    <option value="51">Volvo</option>
    <option value="52">Yugo</option>

   
      </select></td>
  </tr>
  <tr style="">
    <td>Model</td>
    <td ><div id="citydiv"><select name="city">
   <option>Select Model</option>
        </select></div></td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
</table>
</form>
</body>
</html>

 

 

Here is the findCity.php

 

<?php $country=$_REQUEST['country'];
$link = mysql_connect('', '', ''); //changet the configuration in required
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db('');
$query="select city from city where countryid=$country";
$result=mysql_query($query);

?>
<select name="city">
<option>Select Model</option>
<?php while($row=mysql_fetch_array($result)) { ?>
<option value><?=$row['city']?></option>
<? } ?>
</select>

 

 

Okay I changed index to this and it populates the drop down but the second menu does not populate?

 


<form method="post" action="" name="form1">
<table width="60%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="150">Country</td>
    <td  width="150"><select name="country" onChange="getCity('findcity.php?country='+this.value)">

<option>Select Country</option>
<?php while($row=mysql_fetch_array($result)) { ?>
<option value><?=$row['country']?></option>
<? } ?>
</select>
</td>
  </tr>
  <tr style="">
    <td>City</td>
    <td ><div id="citydiv"><select name="city">
   <option>Select Model</option>
        </select></div></td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
</table>
</form>

Link to comment
https://forums.phpfreaks.com/topic/155118-solved-double-drop-down-from-db/
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.