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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing AJAX function correct div name

    My HTML page has 3 divs (showtext1, showtext2, and showtext3). Depending on which radio button I select, I want to set the innerhtml for the correct div. eg if I hit radio1, I want the responding HTML to appear in showtext1. On click for the radio, I pass a parameter that gets loaded into showQuestion as the 2nd parameter.

    Code:
    function showQuestion(url2, str)
    { 
    
    xmlHttp=GetXmlHttpObject()
    	if (xmlHttp==null)
    	{
    	alert ("Browser does not support HTTP Request")
    	return
    	} 
    
    var url=url2;
    url=url+"?sectionid="+str;
    a=str;
    
    xmlHttp.onreadystatechange=stateChanged2;
    xmlHttp.open("POST",url,true);
    xmlHttp.send(null);
    }
    
    
    function stateChanged2() 
    { 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    	{ 
    	//	var a=1;
    	    document.getElementById("showtext" + a).innerHTML=xmlHttp.responseText
    
    	} 
    }
    How can I pass the value of a to stateChanged2 so that I correctly write the value to the correct div?

    Thanks

  • #2
    New to the CF scene
    Join Date
    Aug 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sure enough, I was able to get help. Here is the answer in case anyone is curious:

    Code:
    function showQuestion(url2, str, temp3)
    { 
    
    xmlHttp=GetXmlHttpObject()
    	if (xmlHttp==null)
    	{
    	alert ("Browser does not support HTTP Request")
    	return
    	} 
    
    var url=url2;
    url=url+"?sectionid="+str;
    
    
    //xmlHttp.onreadystatechange=stateChanged2;
    xmlHttp.onreadystatechange= function() { stateChanged2(temp3); };
    xmlHttp.open("POST",url,true);
    xmlHttp.send(null);
    }
    
    
    function stateChanged2(a) 
    { 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    	{ 	
    	
    	    document.getElementById("showtext" + a).innerHTML=xmlHttp.responseText
    
    	} 
    }


  •  

    Posting Permissions

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