Jump to content

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.