473,385 Members | 1,727 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,385 software developers and data experts.

Calling 2 ajax update functions based upon 1 onreadystatechange

129 100+
Hi

I am wanting to call two ajax functions which basically update and filter drop down menus, this is to be executed upon the onreadystatechange of one drop down menu. I have the following code;

ajax code for executing the commands

Expand|Select|Wrap|Line Numbers
  1. var xmlhttp;
  2.  
  3. function callAjax(url,str,divid)
  4. {
  5.     xmlhttp=GetXmlHttpObject();
  6.     if (xmlhttp==null)
  7.     {
  8.         alert ("Browser does not support HTTP Request");
  9.         return;
  10.     }
  11.  
  12.     var url=url;
  13.     url=url+"?"+str;
  14.     url=url+"&sid="+Math.random();
  15.     xmlhttp.onreadystatechange=function()
  16.     {
  17.         if (xmlhttp.readyState==4 && xmlhttp.status==200)
  18.         {
  19.             document.getElementById(divid).innerHTML=xmlhttp.responseText;
  20.         }
  21.     }
  22.     xmlhttp.open("GET",url,true);
  23.     xmlhttp.send(null);
  24. }
  25.  
  26. function GetXmlHttpObject()
  27. {
  28.     if (window.XMLHttpRequest)
  29.     {
  30.         // code for IE7+, Firefox, Chrome, Opera, Safari
  31.         return new XMLHttpRequest();
  32.     }
  33.     if (window.ActiveXObject)
  34.     {
  35.         // code for IE6, IE5
  36.         return new ActiveXObject("Microsoft.XMLHTTP");
  37.     }
  38.     return null;
  39. }
php code for the onreadystatechange element

Expand|Select|Wrap|Line Numbers
  1. <td>';
  2.     $content .= "
  3.     <select id='projectID' name='projectID' style='width:100%;' onchange='callAjax(\"filterProjectTasks.php\", \"q=\"+this.value, \"filterProjectTaskResult\"); callAjax(\"filterProjectSites.php\", \"q=\"+this.value, \"filterProjectSiteResult\");'>
  4.     <option id='default' name='default' value='0'></option>";
  5.     foreach($this->getData('projectList') as $dbProject)
  6.     {
  7.         $checkSelectedResult = '';
  8.         if( $this->getData( 'inputProjectID' ) == $dbProject['projectID'] )
  9.         {
  10.             $checkSelectedResult = "selected='selected'";
  11.         }
  12.         $content .= "
  13.         <option value='{$dbProject['projectID']}' {$checkSelectedResult}>{$dbProject['name']}</option>";
  14.     }                            
  15.     $content .= '
  16.     </select>
  17. </td>
This just lists all the projects, so once i select an option i would like it to filter two drops down menus; project tasks and project sites.

php code for filterprojecttasks.php - seperate file

Expand|Select|Wrap|Line Numbers
  1.     /* FILTERPROJECTTASKS.php
  2.      * ajax code for filtering project tasks within the daily diary form */
  3.  
  4.     require_once('../../../includes/config.php');    
  5.  
  6.     $id=$_GET["q"];
  7.  
  8.     $Task = new ProjectTask();
  9.     $taskList = $Task->getProjectTasksByProject($id);
  10.  
  11.     echo '<select id="taskID" name="taskID">
  12.     <option id="default" name="default" value="0">Please select a task</option>';
  13.     foreach($taskList as $dbTask)
  14.     {
  15.         echo '<option value="'.$dbTask['taskID'].'">'.$dbTask['description'].'</option>';
  16.     }
  17.     echo '</select>';
php code for filterprojectsites.js - seperate file

Expand|Select|Wrap|Line Numbers
  1.     /* FILTERPROJECTSITES.php
  2.      * ajax code for filtering project sites within the daily diary form */
  3.  
  4.     require_once('../../../includes/config.php');    
  5.  
  6.     $id=$_GET["q"];
  7.  
  8.     $Site = new ProjectSite();
  9.     $siteList = $Site->getProjectSitesByProject($id);
  10.  
  11.     echo '<select id="siteID" name="siteID">
  12.     <option id="default" name="default" value="0">Please select a site</option>';
  13.     foreach($siteList as $dbSite)
  14.     {
  15.         echo '<option value="'.$dbSite['siteID'].'">'.$dbSite['name'].'</option>';
  16.     }
  17.     echo '</select>';
php code for the returned results for tasks

Expand|Select|Wrap|Line Numbers
  1. <td>
  2.     <div id="filterProjectTaskResult">
  3.         <select id="taskID_0'.$i.'" name="taskID_0'.$i.'">
  4.             <option id="default" name="default" value="0">Please select a task</option>';
  5.             foreach($this->getData('taskList') as $dbTask)
  6.             {
  7.                 $checkSelectedResult = '';
  8.                 if( $this->getData( 'inputTaskID_0'.$i ) == $dbTask['taskID'] )
  9.                 {
  10.                     $checkSelectedResult = 'selected="selected"';
  11.                 }
  12.                 $content .= '
  13.                 <option value="'.$dbTask['taskID'].'" '.$checkSelectedResult.'>'.$dbTask['description'].'</option>';
  14.             }
  15.         $content .= '
  16.         </select>
  17.     </div>
  18. </td>
as you can see by default i have the task drop down menu selecting all the tasks.

php code for the returned results for sites

Expand|Select|Wrap|Line Numbers
  1. <td>
  2.     <div id="filterProjectSiteResult">
  3.         <select id="siteID_0'.$i.'" name="siteID_0'.$i.'">
  4.             <option id="default" name="default" value="0">Please select a site</option>';
  5.             foreach($this->getData('siteList') as $dbSite)
  6.             {
  7.                 $checkSelectedResult = '';
  8.                 if( $this->getData( 'inputSiteID_0'.$i ) == $dbSite['siteID'] )
  9.                 {
  10.                     $checkSelectedResult = 'selected="selected"';
  11.                 }
  12.                 $content .= '
  13.                 <option value="'.$dbSite['siteID'].'" '.$checkSelectedResult.'>'.$dbSite['name'].'</option>';
  14.             }
  15.         $content .= '
  16.         </select>
  17.     </div>
  18. </td>
as you can see by default i have the site drop down menu selecting all the sites.

When debugging through the console it shows the command being called and executing the correct files with the correct results, however for some reason it does not filter the sites or tasks drop down menu's on screen.

Any help would be greatly appreciated!
Apr 4 '11 #1
0 1022

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

Similar topics

3
by: Micromanaged | last post by:
Is it possible (and if so, how?) to have an asp form page that based upon a user's selection on a field, would generate a input field b that the user selects? For example: User selects "name"...
3
by: TJS | last post by:
looking for generic function to build sql update string for values coming from a form. I've seen these for classic asp but I'm not finding equivalent in asp.net Googleing did not help so far
1
by: Mike P | last post by:
Is it possible when populating a datagrid to populate a dropdownlist column based upon the value populated to another row in the datagrid? (i.e. I have a drop down which I want to populate...
2
by: DanWeaver | last post by:
I have a page where layout of buttons and listboxes etc is important - I would like to make use of Ajax Update panel to asynchronously update various part of the page- in Vis studio whenever I use...
1
by: sajithamol | last post by:
Getting error if i drag and drop ajax update panel in the child page. added scriptmanager proxy to the child page but still getting the same error .In the page added many menu conrols ( created...
1
by: lir | last post by:
I'm stuck with a problem, basically the code works fine in MOZILLA. I call from a <select> tag a ajax.update and successfully it show up everything. However using IE the <select> tag is...
0
by: nityaprashant | last post by:
hello.. i used ajax update panel in my cart form now i want to use paypal button for redirect online transaction because of ajax update panel round trip is not possible.. so paypal button gives...
0
by: Andy B | last post by:
How would you make an ajax update pannel show the key/value pair values inside a dictionary class? I need them in an html definition list if possible.
1
by: Emma Middlebrook | last post by:
Hi, I've implemented an AJAX update panel on one of my ASP.NET web pages. I generate and add controls to it dynamically. What I would like to do is tell it to start a new line before adding the...
0
by: perdijc | last post by:
The wizard to create dataset, automatically creates a method to update table if the dataset is based on table. If i create a dataset based on sotored procedure where this is based on more one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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,...
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
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...

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.