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
AJAXPHPHTML

Avatar of undefined
Last Comment
leakim971

8/22/2022 - Mon
Ray Paseur

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.
Sandeep Kothari

make sure. that showItem function is included in review.php page and not on getreviewinfo.php page...

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>
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
teedo757

ASKER
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.
teedo757

ASKER
Ray_Paseur how would I do this?
ASKER CERTIFIED SOLUTION
Sandeep Kothari

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
teedo757

ASKER
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.
leakim971

thanks for your feedback, have fun and a good week!