By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,921 Members | 1,442 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,921 IT Pros & Developers. It's quick & easy.

More than one ajax functions in a form

P: 5
Hi,

I hav a problem with Ajax and PHP. I had populate a dropdown w.r.t to another dropdown using ajax. But the problem is I hav to list some data on the selected index change that newly created ajax dropdown using AJAX with reloading the page. Where i hav to call the ajax function to list the data?Because That dropdown is created using ajax on another page ..What can I do? Can any one plz help me....Im struggling with that for last three days .....
Thanks in advance..
Jan 24 '08 #1
Share this Question
Share on Google+
5 Replies


rpnew
100+
P: 188
Hi,

I hav a problem with Ajax and PHP. I had populate a dropdown w.r.t to another dropdown using ajax. But the problem is I hav to list some data on the selected index change that newly created ajax dropdown using AJAX with reloading the page. Where i hav to call the ajax function to list the data?Because That dropdown is created using ajax on another page ..What can I do? Can any one plz help me....Im struggling with that for last three days .....
Thanks in advance..
Hi,
Can you explain your problem a bit more.... and provide snap of code which you are using......
However if you want to call the Ajax function on selected index change then obvious thing is that you need to call that function on second dropdown box's onchange event......

Regards,
RP
Jan 24 '08 #2

P: 5
Hi,
Can you explain your problem a bit more.... and provide snap of code which you are using......
However if you want to call the Ajax function on selected index change then obvious thing is that you need to call that function on second dropdown box's onchange event......

Regards,
RP
Hi,
Firstly thanks for the response. Ya,I need to call that function on second dropdown box's onchange event. But that second dropdown is dynamically coming from another page with fully populated thru HTML response and im getting it in the orginal page thru innerhtml. Any way im attaching the code below.Plzz check it out ...


Subtasklist.php (this is my main mage)


<html>
<body>


<SCRIPT LANGUAGE="JavaScript">

var xmlHttp;
function showtask(str)
{

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="gettask.php";

url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{

var s=document.getElementById('txttask'); //getting my div id here

var ss=xmlHttp.responseText;

document.getElementById('txttask').innerHTML=ss;


}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}

</script>



<table width="100%" align="center" cellpadding="0" cellspacing="0" bgcolor="#999999">
<form >
</table>
<table>

<tr>
<td>Projects:</td>
<td>
<select name=ddlproject onchange="showtask(this.value)" >
<option value=0>
<?php


echo "Select";

$query = "SELECT projectCode,projectName FROM projects";
$result = $d->query($query);
while($row = $d->fetch_array($result))
{
?>
<option value="<?php echo $row["projectCode"]?>">
<?php
echo $row["projectName"];
?>
</option>
<?php
}


?>
<?php
echo" </select>" ;

?>


</td>
<td>Task</td>
<td><table ><tr><td id="txttask"><select><option>select</option></select></td></tr></table></td>
</tr>

</table>

</form>

</body>
</html>


Gettask.php
( here is where im creating the new dropdown populated with some data)


<?php
require_once('include/config.php');
require_once('include/configClass.php');
echo"<table><tr><td>
<select name=ddl onchange='showsub(this.value)';>";
?>
<option value=0>
<?php


echo "Select";

$q=$_GET["q"];

$query="SELECT taskCode,taskName FROM phases WHERE projectCode = '".$q."'";
$result = $d->query($query);
while($row = $d->fetch_array($result))
{

?>
<option value="<?php echo $row["taskCode"]?>">
<?php
echo $row["taskName"];
?>
</option>
<?php
}
?>
<?php
echo" </select>" ;

?>
</td></tr></table>



This the way i tried. But what is the further procedure to list some data on the "onchange" event of this dynamically created dropdown. I think now you understand my problem...

Thanks
Jan 26 '08 #3

Markus
Expert 5K+
P: 6,050
Make a function for it then, just as you do with the first ajax function.
Jan 26 '08 #4

rpnew
100+
P: 188
Hi,
Firstly thanks for the response. Ya,I need to call that function on second dropdown box's onchange event. But that second dropdown is dynamically coming from another page with fully populated thru HTML response and im getting it in the orginal page thru innerhtml. Any way im attaching the code below.Plzz check it out ...


Subtasklist.php (this is my main mage)


<html>
<body>


<SCRIPT LANGUAGE="JavaScript">

var xmlHttp;
function showtask(str)
{

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="gettask.php";

url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{

var s=document.getElementById('txttask'); //getting my div id here

var ss=xmlHttp.responseText;

document.getElementById('txttask').innerHTML=ss;


}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}

</script>



<table width="100%" align="center" cellpadding="0" cellspacing="0" bgcolor="#999999">
<form >
</table>
<table>

<tr>
<td>Projects:</td>
<td>
<select name=ddlproject onchange="showtask(this.value)" >
<option value=0>
<?php


echo "Select";

$query = "SELECT projectCode,projectName FROM projects";
$result = $d->query($query);
while($row = $d->fetch_array($result))
{
?>
<option value="<?php echo $row["projectCode"]?>">
<?php
echo $row["projectName"];
?>
</option>
<?php
}


?>
<?php
echo" </select>" ;

?>


</td>
<td>Task</td>
<td><table ><tr><td id="txttask"><select><option>select</option></select></td></tr></table></td>
</tr>

</table>

</form>

</body>
</html>


Gettask.php
( here is where im creating the new dropdown populated with some data)


<?php
require_once('include/config.php');
require_once('include/configClass.php');
echo"<table><tr><td>
<select name=ddl onchange='showsub(this.value)';>";
?>
<option value=0>
<?php


echo "Select";

$q=$_GET["q"];

$query="SELECT taskCode,taskName FROM phases WHERE projectCode = '".$q."'";
$result = $d->query($query);
while($row = $d->fetch_array($result))
{

?>
<option value="<?php echo $row["taskCode"]?>">
<?php
echo $row["taskName"];
?>
</option>
<?php
}
?>
<?php
echo" </select>" ;

?>
</td></tr></table>



This the way i tried. But what is the further procedure to list some data on the "onchange" event of this dynamically created dropdown. I think now you understand my problem...

Thanks

hi,

You can do the same as you've done with the first dropdown box..

Now on your Gettask.php page you are creating another dropdown box which you are loading on main page... right?
On Gettask.php you have one line shown below......
[PHP]
<select name=ddl onchange='showsub(this.value)';>";
[/PHP]

here you are using one function on onchange event(showsub(this.value))...... in main page create its definition...

Regards,
RP
Jan 28 '08 #5

Markus
Expert 5K+
P: 6,050
And use code tags when posting code.
Jan 28 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.