Link to home
Start Free TrialLog in
Avatar of teedo757
teedo757

asked on

using onchange after ajax call

If I have a page called review.php and on that page the user selects a job and hits submit, it calls an ajax function that gets all the job information from getreviewinfo.php and pastes that info into a div tag on the review.php page.

review.php --> getreviewinfo.php (Gets order information) Ajax

review.php <-- table with order info is passed back

Withing the table is another ajax lookup function to find available items, it is triggered by an onchange="showItem(this.value)


This does not work and I am not sure if the onchange will not work since the table was created on the getreview.php page and not the review.php page which is where the user will interact. Any help would be great, thanks
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

I'm wondering if you might get better results by putting the second AJAX lookup function into a separate div and passing back two updates from getreviewinfo.  That way the onChange would already be part of the DOM when the page was loaded.
make sure. that showItem function is included in review.php page and not on getreviewinfo.php page...

Avatar of teedo757
teedo757

ASKER

......ya its on the getreviewinfo.php page. Not sure if there is a way to put it on the review.php page.

Is there a some way to keep the ajax session open to look for a change?

Some code:


<!-- this is the drop down
<select name="itemcatsearch" id="category" size="1" onchange="showItem(this.value)">
 <option value="0" selected="selected" >Please Select Category</option>
              <option value="audio" >Audio</option>
              <option value="decor">Decor</option>
              <option value="fx">Fx</option>
              <option value="lighting">Lighting</option>
              <option value="power">Power</option>
              <option value="rigging">Rigging</option>
              <option value="video">Video</option>
              </select></td>



<!--Function to call getitem.php to fill the item drop down box --------------------------------------------------------------->
<script type="text/javascript">
function showItem(str)
{
if (str=="")
  {
  document.getElementById("txtItem").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtItem").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getitemcus.php?catagory="+str,false);
xmlhttp.send();
}
</script>
Its setup as three drop down boxes.

catagory --> item --> Qty

Then there is an add button that adds the product to the order.

I want the review page to allow any adds to an order so I wanted to include this functionality.
Ray_Paseur how would I do this?
ASKER CERTIFIED SOLUTION
Avatar of Sandeep Kothari
Sandeep Kothari
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of leakim971
in your original getreviewinfo.php, replace :
<script type="text/javascript">
function showItem(str)

Open in new window

by:
<script type="text/javascript">
showItem = function(str)

Open in new window

leakim971 I tried your fix and it did not seem to do anything. kshna answer did not fix everything but it did make that section work.
thanks for your feedback, have fun and a good week!