473,804 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

More than one ajax functions in a form

5 New Member
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 2117
rpnew
188 New Member
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
phpachu
5 New Member
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="JavaS cript">

var xmlHttp;
function showtask(str)
{

xmlHttp=GetXmlH ttpObject();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="gettask.ph p";

url=url+"?q="+s tr;
url=url+"&sid=" +Math.random();
xmlHttp.onready statechange=sta teChanged;
xmlHttp.open("G ET",url,true) ;
xmlHttp.send(nu ll);
}
function stateChanged()
{
if (xmlHttp.readyS tate==4 || xmlHttp.readySt ate=="complete" )
{

var s=document.getE lementById('txt task'); //getting my div id here

var ss=xmlHttp.resp onseText;

document.getEle mentById('txtta sk').innerHTML= ss;


}
}
function GetXmlHttpObjec t()
{
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.XMLHT TP");
}
}
return xmlHttp;
}

</script>



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

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


echo "Select";

$query = "SELECT projectCode,pro jectName FROM projects";
$result = $d->query($query );
while($row = $d->fetch_array($r esult))
{
?>
<option value="<?php echo $row["projectCod e"]?>">
<?php
echo $row["projectNam e"];
?>
</option>
<?php
}


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

?>


</td>
<td>Task</td>
<td><table ><tr><td id="txttask"><s elect><option>s elect</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('i nclude/config.php');
require_once('i nclude/configClass.php ');
echo"<table><tr ><td>
<select name=ddl onchange='shows ub(this.value)' ;>";
?>
<option value=0>
<?php


echo "Select";

$q=$_GET["q"];

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

?>
<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 Recognized Expert Expert
Make a function for it then, just as you do with the first ajax function.
Jan 26 '08 #4
rpnew
188 New Member
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="JavaS cript">

var xmlHttp;
function showtask(str)
{

xmlHttp=GetXmlH ttpObject();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="gettask.ph p";

url=url+"?q="+s tr;
url=url+"&sid=" +Math.random();
xmlHttp.onready statechange=sta teChanged;
xmlHttp.open("G ET",url,true) ;
xmlHttp.send(nu ll);
}
function stateChanged()
{
if (xmlHttp.readyS tate==4 || xmlHttp.readySt ate=="complete" )
{

var s=document.getE lementById('txt task'); //getting my div id here

var ss=xmlHttp.resp onseText;

document.getEle mentById('txtta sk').innerHTML= ss;


}
}
function GetXmlHttpObjec t()
{
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.XMLHT TP");
}
}
return xmlHttp;
}

</script>



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

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


echo "Select";

$query = "SELECT projectCode,pro jectName FROM projects";
$result = $d->query($query );
while($row = $d->fetch_array($r esult))
{
?>
<option value="<?php echo $row["projectCod e"]?>">
<?php
echo $row["projectNam e"];
?>
</option>
<?php
}


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

?>


</td>
<td>Task</td>
<td><table ><tr><td id="txttask"><s elect><option>s elect</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('i nclude/config.php');
require_once('i nclude/configClass.php ');
echo"<table><tr ><td>
<select name=ddl onchange='shows ub(this.value)' ;>";
?>
<option value=0>
<?php


echo "Select";

$q=$_GET["q"];

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

?>
<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='shows ub(this.value)' ;>";
[/PHP]

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

Regards,
RP
Jan 28 '08 #5
Markus
6,050 Recognized Expert Expert
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
4052
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, http://www.w3schools.com/ajax/ajax_source.asp, only my array is populated from info pulled from db.. I added interface to HTML interface to insert info into db; info gets inserted in to db in a servlet then servlet redirects back to HTML interface, where if user types something from...
0
990
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 the amount of coding to do on building maintenance pages. All forms will recall or create a single record in a table. The table will always have a unique key of one field which will always be the first field in the record. The record could...
1
1991
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 using ajax. This is on an IIS server and all ajax has just been downloaded and installed and functions with simple ajax web pages) The map worked fine except the original script in C# uses a response.write: (ie) Response.Write("<form...
2
3174
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 i change something in php file using in ajax function.it not refreshed,means its shows the previous result it not get updated.i can't understand whats the prob.this is the code i m using: <? include("config.inc.php"); //error_reporting(0); ...
7
10297
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 lack some JavaScript solid knowdlege) The problem is that when I try to send a form's content with Ajax (I'm using the prototype library), for some reason the latin characters (accents and stuff, like áéíóú) turn a mess when I try to store them in...
1
4439
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 content from the database via AJAX is no problem, that works and thickbox works too, I'm just having problems getting them both running together! It seems like it's too much information to cram into one poor little "a href=".... the "onclick"...
5
4469
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 if I have the entirely wrong approach, but my code is below. Any or all help is appreciated! What currently happens is that the getdivision.php script works perfectly and gives me an entire table of correct data. The problem is that when I click...
5
2672
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 listboxes that are chained together. In other words, if you click on the first one it filters out what's available in the next three. If you click on the 3rd one, it filters out the available options in the 4th one, etc. I do this by having php pages...
0
9711
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9593
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10088
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9169
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7633
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.