klosie Posted August 31, 2009 Share Posted August 31, 2009 Hi i need help I am making a dropdown list with ajax and php, everything is ok except for the results of the second dropdown.. When i choose an option the dropdown appears withou any value in it. Here i post my code, i hope someone can help me and tell me what i am doing wrong. AJAX var xmlhttp; function showUser(str) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="ajaxcalling.php"; url=url+"?q="+str; url=url+"&sid="+Math.random(); xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function stateChanged() { if (xmlhttp.readyState==4) { document.getElementById("proyectos").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari XMLHttpRequest.overrideMimeType('text/xml'); return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } PHP <?php $q = $_GET['catname']; echo "<td align=\"right\"><b>Proyecto:</b></td> "; echo "<td><select name=\"subcatname\">"; $querycat4 = "SELECT subcatname FROM proyectos WHERE catname ='".$q."'"; $resultcat4 = mysql_query($querycat4) or die ("Couldn't execute query - CATECON.PHP"); while($rowcat4 = mysql_fetch_array($resultcat4)) { $subcatname = $rowcat4['subcatname']; echo "<OPTION value=\"$subcatname\">$subcatname</OPTION>"; } echo "</select></td></tr>"; ?> and the place where it suppose to appear echo "<table bgcolor=\"#ECECEC\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\" class=\"black\" border=\"0\">"; echo "<tr><td bgcolor=\"#ECECEC\" align=\"center\"><b>Crear tarea</b></td><td bgcolor=\"#F2F2F2\" align=\"center\"><b>Clientes</b></td></tr>"; echo "<tr><td>"; echo "<table bgcolor=\"#ECECEC\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\" class=\"black\">"; echo "<tr><form name=\"form1\" method=\"post\" onSubmit=\"return (formCheck(this))\" action=\"complete.php?getid=1\">"; echo "<td align=\"right\"><b>Cliente:</b></td> "; echo "<td><select name=\"catname\" onchange=\"showUser(this.value)\" >"; include 'includes/catecon.php'; echo "</select></td></tr>"; echo "<div id=\"proyectos\"></div>"; Link to comment https://forums.phpfreaks.com/topic/172596-ajax-php-dropdown-list/ Share on other sites More sharing options...
klosie Posted September 1, 2009 Author Share Posted September 1, 2009 nobody? Link to comment https://forums.phpfreaks.com/topic/172596-ajax-php-dropdown-list/#findComment-910424 Share on other sites More sharing options...
kickstart Posted September 1, 2009 Share Posted September 1, 2009 Hi That the drop down appears but with nothing in it suggests that the AJAX stuff is working, just that there are no matching records for the catname passed through. However you appear to pass a variable called q in the URL, but the php expects one called catname. All the best Keith Link to comment https://forums.phpfreaks.com/topic/172596-ajax-php-dropdown-list/#findComment-910427 Share on other sites More sharing options...
klosie Posted September 1, 2009 Author Share Posted September 1, 2009 i've changed it and nothing, the dropdown is empty. So i am guessing what i have wrong is my php script.. but i can't find my error. Link to comment https://forums.phpfreaks.com/topic/172596-ajax-php-dropdown-list/#findComment-910482 Share on other sites More sharing options...
kickstart Posted September 1, 2009 Share Posted September 1, 2009 Hi Echo out $querycat4 and see what it contains. And try copying it out and executing that directly in mysql. All the best Keith Link to comment https://forums.phpfreaks.com/topic/172596-ajax-php-dropdown-list/#findComment-910557 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.