Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Change div content onclick with AJAX

    I have a page with a list of properties, on each property is a view more link. When this link is pressed I want to be able to expand the box with more content which resides on an external page.

    I have got it so that one div is changing, but because there are multiple listings, I need a unique id for each div.

    I've currently got:

    Code:
    <script type="text/javascript">
    
    var xmlHttp
    
    function showDetail(intID) {
    
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
      {
      alert ("Your browser does not support AJAX!");
      return;
      } 
    var url="lettings-detail.asp";
    url=url+"?id="+intID;
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    } 
    
    function stateChanged() 
    { 
    if (xmlHttp.readyState==4)
    { 
    document.getElementById("detail_box"+intID).innerHTML=xmlHttp.responseText;
    }
    }
    
    function GetXmlHttpObject()
    {
    var xmlHttp=null;
    try
      {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      }
    catch (e)
      {
      // Internet Explorer
      try
        {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e)
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      }
    return xmlHttp;
    } 
    
    
    </script>
    Then on the page:

    <a href="#" class="detail" onclick="showDetail('<%=RS("propID")%>'); return false;">view details</a>

    <div id="detail_box<%=RS("propID")%>"></div>

    I can't seem to pass the intID value into the stateChanged function to get a unique div id??

    Also how would I go about toggling the view details link to remove the div again?

    Many thanks

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    How about
    Code:
    xmlHttp.onreadystatechange=function (){
    stateChanged(intID);
    }
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Jun 2002
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ahh, almost, it was that and then when the function was called it was:

    function stateChanged(intID)

    Any ideas how to do the toggle?

    Thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •