473,407 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

More than one ajax functions in a form

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
5 2090
rpnew
188 100+
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
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
6,050 Expert 4TB
Make a function for it then, just as you do with the first ajax function.
Jan 26 '08 #4
rpnew
188 100+
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
6,050 Expert 4TB
And use code tags when posting code.
Jan 28 '08 #6

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

Similar topics

4
by: Frances | last post by:
I literally started learning AJAX just last weekend.. I have this page, http://www.francesdelrio.com/ajax/db2.html, where I'm essentially doing what's here,...
0
by: frothpoker | last post by:
Hi guys, hope you can help me here... i am building a new on-line application unsing L.A.M.P. and ajax. I have a number of static tables which need to be maintained and want to try to cut down...
1
by: JWHIT | last post by:
I created a map application which works fine with regular aspx and a meta refresh. I would like to have the map itself update independently using ajax. (Sorry on the long post, I just started...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
7
xNephilimx
by: xNephilimx | last post by:
lHi guys! I'm having a little problem that's getting on my nerves, I couldn't find a solution, I also tryed googling it and I found nothing... (my field of expertise is in AS 2 and 3, but I still...
1
by: fidgen | last post by:
Hiya, I'm trying to get a AJAX driven update to my list of news articles, so when users click the title of the news article, it pops up the article content in a thickbox overlay. Retrieving...
5
by: thatcollegeguy | last post by:
Below are my 3php and 2js files. I create a table using ajax/php and then want to change the values in the tables add(+ number for teamid) id's for each specific td in the table. I don't know...
5
by: MelindaM | last post by:
Hi guys, I created a form for searching through a parts library that I have stored in a MySQL database. I'm not new to web programming but this is my first time using PHP and Ajax. I have four...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.