sandbudd Posted April 21, 2009 Share Posted April 21, 2009 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? <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> <?php $link = mysql_connect('', '', ''); //changet the configuration in required if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db(''); $query="select * from country"; $result=mysql_query($query); ?> <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> Quote Link to comment https://forums.phpfreaks.com/topic/155111-solved-double-drop-down-from-db/ Share on other sites More sharing options...
gevans Posted April 21, 2009 Share Posted April 21, 2009 The problem's with your ajax, try asking in the javascript section.... Once that's sorted you may need to revise the php also Quote Link to comment https://forums.phpfreaks.com/topic/155111-solved-double-drop-down-from-db/#findComment-815971 Share on other sites More sharing options...
sandbudd Posted April 21, 2009 Author Share Posted April 21, 2009 will do thanks Quote Link to comment https://forums.phpfreaks.com/topic/155111-solved-double-drop-down-from-db/#findComment-815976 Share on other sites More sharing options...
sandbudd Posted April 21, 2009 Author Share Posted April 21, 2009 Posted...there is no one over there...lol Quote Link to comment https://forums.phpfreaks.com/topic/155111-solved-double-drop-down-from-db/#findComment-815985 Share on other sites More sharing options...
soak Posted April 22, 2009 Share Posted April 22, 2009 You're calling findcity.php but you indicate your file is called findCity.php. If you're on Windows this will be fine but not on nix. There's nothing obvious wrong with your javascript. What happens if you view findcity.php?id=1 in your browser? Quote Link to comment https://forums.phpfreaks.com/topic/155111-solved-double-drop-down-from-db/#findComment-816013 Share on other sites More sharing options...
sandbudd Posted April 22, 2009 Author Share Posted April 22, 2009 404 error not found Quote Link to comment https://forums.phpfreaks.com/topic/155111-solved-double-drop-down-from-db/#findComment-816027 Share on other sites More sharing options...
sandbudd Posted April 22, 2009 Author Share Posted April 22, 2009 sorry my bad...just shows the drop down not populated Quote Link to comment https://forums.phpfreaks.com/topic/155111-solved-double-drop-down-from-db/#findComment-816031 Share on other sites More sharing options...
sandbudd Posted April 22, 2009 Author Share Posted April 22, 2009 and it is findcity.php not findCity.php Quote Link to comment https://forums.phpfreaks.com/topic/155111-solved-double-drop-down-from-db/#findComment-816032 Share on other sites More sharing options...
sandbudd Posted April 22, 2009 Author Share Posted April 22, 2009 now if I do this findcity.php?country=1 it pulls the correct information Quote Link to comment https://forums.phpfreaks.com/topic/155111-solved-double-drop-down-from-db/#findComment-816036 Share on other sites More sharing options...
sandbudd Posted April 22, 2009 Author Share Posted April 22, 2009 if its not in the javascript then I cant seem to find the problem Quote Link to comment https://forums.phpfreaks.com/topic/155111-solved-double-drop-down-from-db/#findComment-816084 Share on other sites More sharing options...
sandbudd Posted April 22, 2009 Author Share Posted April 22, 2009 this is what worked <? while($row=mysql_fetch_array($result)) { ?> <option value="<?=$row['id']?>"><?=$row['country']?></option> <? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/155111-solved-double-drop-down-from-db/#findComment-816088 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.