hey ppl,
I want to open up a list box with the values equal to the selection from the first and the second list boxes I have. Since I wan the list box to be displayed on the same page i am using AJAX.
Here is the code for the first list box in PHP:
<?php
Untitled-3.php
mysql_connect("") or die(mysql_error());
mysql_select_db("") or die(mysql_error());
$Project=@$_GET['Project'];
$Assignment=@$_GET['Assignment'];
$User=@$_GET['User'];
$sql="SELECT Project_Id,ProjectName FROM Project";
$result=mysql_query($sql);
echo "<select name='Project' size='4' multiple='multiple' onchange=showUser(this.value)>";
echo "<option selected='selected'>Select Project</option>";
while ($row=mysql_fetch_array($result)) {
echo "<OPTION VALUE=$row[Project_Id]>$row[ProjectName]</option>";
}
echo"</select>";
?>
//Code for Second List box
Untitled-4.php
<?php
mysql_connect("") or die(mysql_error());
mysql_select_db("") or die(mysql_error());
$Project_Id=$_GET['Project_Id'];
$sql1="SELECT Project_Id, TodoList FROM assign WHERE Project_Id='$Project_Id'";
$result1=mysql_query($sql1);
echo "<select name=Assignment size=4 multiple=multiple onchange=showDetails(this.value)>";
echo "<option selected=selected>Select Assignment</option>";
while ($row1=mysql_fetch_array($result1)) {
echo "<OPTION VALUE=$row1[TodoList]>$row1[TodoList]</option>";
}
echo"</select>";
?>
//Here is the problem... I want the third listbox with the values //corresponding to the selection from the first two list box... I am //getting a blank table, eventhough i have values in the database to be //displayed
//The PHP code for the third list box is:
//Untitled-5.php
<?php
$Project_Id=$_GET['Project_Id'];
$TodoList=$_GET['TodoList'];
mysql_connect("") or die(mysql_error());
mysql_select_db("") or die(mysql_error());
$sql2="SELECT Project_Id, TodoList, Username FROM assign WHERE TodoList='$TodoList' and Project_Id='$Project_Id' ";
$result2=mysql_query($sql2);
echo "<select name=User size=4 multiple=multiple onchange=showDetails1(this.value)>";
echo "<option selected=selected>Select User</option>";
while ($row2=mysql_fetch_array($result2)) {
echo "<OPTION VALUE=$row2[Username]>$row2[Username]</option>";
}
echo"</select>";
?>
//My AJAX Code is:
//selectuser.js
var xmlhttp;
function showUser(Project_Id)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="Untitled-4.php";
url=url+"?Project_Id="+Project_Id;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function showDetails(TodoList, Project_Id)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="Untitled-5.php";
url=url+"?Project_Id="+Project_Id+"&TodoList="+TodoList+"";
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=todoChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
function todoChanged()
{
if(xmlhttp.readystate==4)
{
document.getElementById("main").innerHTML=xmlhttp.responsetext;
}
}
function GetXmlHttpObject()
{
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
HELP IS MUCH APPRECIATED...
THANKS IN ADVANCE...