Solved

Clear Div before Ajax loads

Posted on 2010-08-27
3
693 Views
Last Modified: 2012-05-10
I am using the ajax script below to populate the div "txtHint"...The script returns everything that is echoed in the update_chauffer.php page. I need to clear the div "txtHint" before ajax loads and displays the information again. Basically I am inserting information into mysql then running a query to display information based on the query so I am continually adding to the query results...Thanks
<script type="text/javascript">
function UpdateChauffer(str)
{
if (str=="")
  {
  document.getElementById("txtHint").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("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","update_chauffer.php?ride=<? echo $_GET['id']; ?>&q="+str,true);
xmlhttp.send();
}
</script>

Open in new window

0
Comment
Question by:brad0525
  • 2
3 Comments
 
LVL 11

Expert Comment

by:Amar Bardoliwala
ID: 33540733
Hello brad0525,

Your script seems fine currently.

Can you please tell exactly  what problem are you getting?

Thanks.

Amar.
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 33540853
Currently you do the job only if str is empty :

function UpdateChauffer(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";

we may do it all time :

function UpdateChauffer(str)
{
  document.getElementById("txtHint").innerHTML="";
if (str=="")
  {

If you don't see the content cleared this is because you're don't clear the right div, perhaps you more than one or need to clear a parent div
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33659427
You're welcome! Thanks for the points!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now