dubsqd Posted August 16, 2011 Share Posted August 16, 2011 default.php <script type="text/javascript"> function showSalespersons(str) { if (str=="" || str==0) { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","components/com_elog/views/elog/tmpl/getsalespersons.php?q="+str,true); xmlhttp.send(); } </script> <?php $db =& JFactory::getDBO(); $query = "SELECT * FROM #__elog_dealers"; $db->setQuery($query); $dealers = $db->loadObjectList(); ?> <h1>Remove Salesperson</h1> <form action="index.php?option=com_elog&view=elog&layout=deletesalesperson" method="post" name="deletesalesperson"> <table> <tr> <td>Dealer:</td> <td> <select name="dealerid" style="width: 200px" onChange="showSalespersons(this.value)"> <?php echo "<option value=\"0\"></option>"; foreach($dealers as $dealer) { echo "<option value=\"".$dealer->id."\">".$dealer->name."</option>"; } ?> </select> </form> </td> </tr> <tr> <td>Salesperson:</td> <td><div id="txtHint"><b>Please select a dealer. Salespersons will be listed here.</b></div></td> </tr> </table> getsalespersons.php <?php $q=$_GET["q"]; $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("elog", $con); $sql = "SELECT * FROM jos_elog_salespersons WHERE dealerid = '".$q."' ORDER BY name ASC"; $result = mysql_query($sql); echo "<select name=\"salespersons\" style=\"width: 200px\">"; echo "<option value=\"0\"></option>"; while($row = mysql_fetch_array($result)) { echo "<option value=\"".$row['id']."\">".$row['name']."</option>"; } echo "</select>"; mysql_close($con); ?> My question is pretty simple. I don't know why but when I put the <div id="txtHint"> inside the form it doesn't work. If I put it outside the form it works fine. The thing is I need to use the value selected by the user in the salespersons drop down in the form. Is there any way I can do that? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/244939-how-to-use-value-returned-by-ajax/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.