Hey ppl,

I have a couple of php codes for displaying the list box, depending on the selection from the first list box... I am trying to diplay all the list box on the same page using AJAX

The problem is, My first , second & the third list box gets filled properly, but there is problem with the fourth list box... My fourth list box is not getting filled at all...

my PHP codes are as follows

Untitled-3.php

<?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>";
?>
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>";
?>
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'"; 
$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>";
?>
Untitled-6.php

<?php

$Username=$_GET['Username'];
$Project=$_GET['Project_Id'];
$TodoList=$_GET['TodoList'];

mysql_connect("") or die(mysql_error()); 
mysql_select_db("") or die(mysql_error()); 


$sql3="SELECT WorkDone, Username, Project_Id FROM WD WHERE Username='$Username' and Project_Id='$Project' and TodoList='$TodoList'"; 
$result3=mysql_query($sql3); 

echo "<select name=User size=4 multiple=multiple>";
echo "<option selected=selected>Work Done by $Username</option>";

while ($row3=mysql_fetch_array($result3)) { 

    echo "<OPTION VALUE=$row3[WorkDone]>$row3[WorkDone]</option>";
    } 
echo"</select>";
?>

The AJAX Code is as follows:

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 showDetails1(Username, TodoList, Project_Id)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="Untitled-6.php";
url=url+"?Project_Id="+Project_Id+"&TodoList="+TodoList+"&Username="+Username+"";
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=userChanged;
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 userChanged()
{
if(xmlhttp.readystate==4)
{
document.getElementById("main1").innerHTML=xmlhttp.responsetext;
}
}


function GetXmlHttpObject()
{
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

Thanks in advance...

I couldn't find any errors, try to put some alert messages in the function userChanged(); and check what output you are getting from xmlhttp.responsetext.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.