html - form onchange AJAX function for PHP database query -


i quite new ajax , appreciate help. have been trying use ajax onchange of first drop down menu call function php query database , populate matching results second drop down menu. db connect script works fine, , php query accurately pulls correct info database. (when not using posted variable $cityinput) problem has been getting result php ajax, , displayed in second drop down menu.

<?php require'connect.php';  $cityinput=$_post['cityinput'];  $query="select mname masseurs lounge='$cityinput'"; $result=mysql_query($query); $num=mysql_numrows($result);  echo "<b><center>database output</center></b><br><br>"; $i=0; while ($i < $num) { $mname=mysql_result($result,$i,"mname");  $mname="<option value=''>"mname"</option>"; $i++;}  if (!mysql_query($query))   {die('error: ' . mysql_error());} mysql_close(); ?>       <html> <head> <script> function getmasseurs() {if (str=="")   {document.getelementbyid("masseurinput").innerhtml="";   return;   }  if (window.xmlhttprequest)   {// code ie7+, firefox, chrome, opera, safari   xmlhttp=new xmlhttprequest();   } else   {// code ie6, ie5   xmlhttp=new activexobject("microsoft.xmlhttp");   } xmlhttp.onreadystatechange=function()   {   if (xmlhttp.readystate==4 && xmlhttp.status==200)     {     document.getelementbyid("masseurinput").innerhtml=xmlhttp.responsetext;     }   } xmlhttp.open("get","outputpopulate3.php?$mname="+str,true); xmlhttp.send(); } </script>   </head> <body> <form id="book" action="test.php" method="post">   <p align="center">      <select name="cityinput" id="cityinput" onchange="getmasseurs()">       <option value="0" selected>city</option>       <option value="1">brisbane</option>       <option value="2">sydney</option>       <option value="3">melbourne</option>       <option value="4">adelaide</option>       <option value="5">perth</option>     </select>   </p>   <p align="center">      <select name="masseurinput" size="1" id="masseurinput"><div id="cityinput"></div>      </select>   </p>   <p align="center">      <input type="submit"> </form></p> </body> </html> 

this appears wrong: xmlhttp.open("get","outputpopulate3.php?$mname="+str,true); file outputpopulate3.php? top one? if not post code of file

why using variable in ? $mname. can't use php code inside of javascript.

if want should use:

xmlhttp.open("get","outputpopulate3.php?<? echo $mname; ?>="+str,true); 

also, 'str' variable in line never set.. can set in previous line:

str = document.getelementbyid('masseurinput').value; 

but easier use fixed variable name..


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -