Advertisement

07.06.2008 at 06:45AM PDT, ID: 23541622
[x]
Attachment Details

Collapsing div still executes code - how do I only execute code when the div is expanding?

Asked by georgep7 in Asynchronous Javascript and XML (AJAX), JavaScript

Hi, I have the following repeating code in a web page:

<a href="#null" onclick="getdetails('111_<%=thefirstcounter%>')"/><%=thefirstcounter%></a></td>
<div id="111_<%=thefirstcounter%>" style="display:none;">
<img src="images/loading.gif" /> <font color="red"> Executing, please wait</font>
</div>

part of the javascript is as follows:

var ImRunning = false;

function getdetails(counter)
{
  if (!ImRunning) {
    ImRunning = true;
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null) {
      alert ("Your browser does not support AJAX!");
      ImRunning = false;
      return;
    }
var url="getdetails.asp";
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
theCounter = counter;
showHide();
xmlHttp.send(null);
}
}

function stateChanged()
{
if (xmlHttp.readyState==4)
{
var whatWasReturned = xmlHttp.responseText;
var pos = whatWasReturned.indexOf("vvvvv");
if (pos == -1)
{
document.getElementById(theCounter).innerHTML=xmlHttp.responseText;
ImRunning = false;
}
else
{
ImRunning = false;
window.location = "http://www.google.com";
}
}
}      

function showHide()
{      
if (theCounterNextNext == "")
{
      window.location.href = "http://www.google.com"
}
else
{
if (document.getElementById(theCounter).style.display == 'none')
{
document.getElementById(theCounter).style.display = '';
}
else
{
document.getElementById(theCounter).style.display = 'none';
}
}
}

One thing I've noticed is that whether you expand or collapse each div, the page getdetails.asp gets executed. How can I adjust the code above so that the getdetails.asp page is only executed when I'm exanding the div?Start Free Trial
 
Loading Advertisement...
 
[+][-]07.06.2008 at 07:03AM PDT, ID: 21940372

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Asynchronous Javascript and XML (AJAX), JavaScript
Sign Up Now!
Solution Provided By: HonorGod
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.06.2008 at 07:54AM PDT, ID: 21940507

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.06.2008 at 10:56AM PDT, ID: 21941089

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.06.2008 at 04:28PM PDT, ID: 21941991

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.07.2008 at 03:13AM PDT, ID: 21943746

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.08.2008 at 04:25AM PDT, ID: 21952634

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628