Solved

Clear Div before Ajax loads

Posted on 2010-08-27
3
700 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

628 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