0

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

Edited by kuteinheart: n/a

5
Contributors
8
Replies
9
Views
7 Years
Discussion Span
Last Post by UzuNarU
0

I don't know how others are seeing this, but my take is that you're making it a lot of work to help you. For instance...based only on what you've given, I'd say that there's no unifying file that includes the javascript file or the individual select boxes.

That aside, you might put in some alert feedback in your javascript code to make sure that your sending url is properly formatted and that you're receiving a response. Also...check your server error logs for hints as to why this is breaking. The problem is often in the server-side files during processing, and that will not show up anywhere but your error logs.

Edited by jmo: n/a

0

Hi

WHat do you mean by there is no unifying file that include the javascript file...?

I don't know how others are seeing this, but my take is that you're making it a lot of work to help you. For instance...based only on what you've given, I'd say that there's no unifying file that includes the javascript file or the individual select boxes.

That aside, you might put in some alert feedback in your javascript code to make sure that your sending url is properly formatted and that you're receiving a response. Also...check your server error logs for hints as to why this is breaking. The problem is often in the server-side files during processing, and that will not show up anywhere but your error logs.

0

Hi

WHat do you mean by there is no unifying file that include the javascript file...?

You show your javascript as being in a file called selectuser.js. To use this, it would be called by the page that the user requests.

Maybe I'm misunderstanding your process, so let me go over what I understand from this, and you can correct me where I'm wrong...

You want a list box displayed when the page loads, built from Untitled-3.php. This file, along with your javascript, must be loaded into the displaying page for the user to view. The user makes a selection on that box, and you use an Ajax call to Untitled-4.php, which then shows a second select box based on selections made from the first one. Then, a selection on the second select box triggers an Ajax call to Untitled-5.php to build the third select box.

If that flow is correct, and these are the only files involved in the process, then the first problem is that the javascript is not present on the client side.

Edited by jmo: n/a

0

I have included this,

<script type="text/javascript" src="selectuser4.js"></script>

So there is no problem with that... There is some problem with the code...

You show your javascript as being in a file called selectuser.js. To use this, it would be called by the page that the user requests.

Maybe I'm misunderstanding your process, so let me go over what I understand from this, and you can correct me where I'm wrong...

You want a list box displayed when the page loads, built from Untitled-3.php. This file, along with your javascript, must be loaded into the displaying page for the user to view. The user makes a selection on that box, and you use an Ajax call to Untitled-4.php, which then shows a second select box based on selections made from the first one. Then, a selection on the second select box triggers an Ajax call to Untitled-5.php to build the third select box.

If that flow is correct, and these are the only files involved in the process, then the first problem is that the javascript is not present on the client side.

0

I have included this,

<script type="text/javascript" src="selectuser4.js"></script>

So there is no problem with that... There is some problem with the code...

Okay...there's still no file to support the javascript. It fails on the onChange event in the first text box. showUser() calls stateChanged() which needs some page element with the id 'txtHint' and that doesn't exist.

I'll be glad to help with finding what's broken, but I get paid to write code for people :). What you have given--if that is all of your code--is broken because it's incomplete.

0

Perhaps if you showed the head area of both php files? Also have you done as suggested by planting multiple alerts in your js to check progress and variable values? Place one in your js file outside the functions so that it runs on page load. If it doesn't, it means that your js file isn't referenced properly.

0

Is this still unsolved? If it is I may be able to re-write the code so it works and is fully AJAX. But if it's solved I don't want to waste time. LoL

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.