Jump to content

2nd drop down list


wright67uk

Recommended Posts

In the coe below the status of the drop down list is passed to the $q variable and used in an sql query.

 

In what way would I change the code if I wanted to have a second drop down?

 

xmlhttp.open("GET","getuser.php?q="+str,true);

xmlhttp.send();

 

<html>
<head>
<script>
function showUser(str)
{
if (str=="")
 {
 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","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>


<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="1">Peter Griffin</option>
<option value="2">Lois Griffin</option>
<option value="3">Glenn Quagmire</option>
<option value="4">Joseph Swanson</option>
</select>
</form>
<br>
<div id="txtHint"><b>Person info will be listed here.</b></div>


</body>
</html>

Link to comment
Share on other sites

what do you mean? you want the returned data from the ajax call to be in a dropdown? in that case just create a dropdown, like so:

 

 
$personID = $_GET['q'];
//use this $personID in your query
$rs = mysql_query($sql);
$content = '<form><select name="secondDropdown" onchange="anotherFunction(this.value)">';
while ($row = mysql_fetch_assoc($rs)) {
$content .= '<option value="'.$row['ID'].'">'.$row['name'].'</option>';
}
$content .= /// close form
echo $content;

Link to comment
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.