Calling Multiple Functions onclick Javascript not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ankita551989
    New Member
    • Jan 2012
    • 2

    Calling Multiple Functions onclick Javascript not working

    I am trying to fill two div tag on the body onload event.One div contains categories other contains subcategories. I am trying to trigger two functions and fill these div through ajax.I guess both functions are executed but the output of second function overwrites the first function. thus i am able to see results of only one function

    This is my code:

    Code:
    <body onLoad="showContentUsingAJAX();showContext();">
    and these are the functions:

    Code:
    function showContentUsingAJAX()
    {
    	urlfield			=	"maincategories.php";	//File path which is to be open
    	params				= 	"pseudoParam="+new Date().getTime();// pseudoparams
    	http.open("POST", urlfield, true);
    	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    	http.setRequestHeader("Content-length", params.length);
    	http.setRequestHeader("Connection", "close");
    	http.onreadystatechange = function()
    	{	
    		if(http.readyState == 4 && http.status == 200)
    		{
    			var results	=	http.responseText;
    			document.getElementById("id1").innerHTML = results;
    			//setAndExecute("DIVNAME", results);
    		}
    	}            
    	http.send(params);
    	
    }
    function showContext()
    {
    	urlfield1			=	"SUBCAT.PHP?catid=1&level=1";	//File path which is to be open
    	params1				= 	"pseudoParam="+new Date().getTime();// pseudoparams
    	http.open("GET", urlfield1, true);
    	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    	http.setRequestHeader("Content-length", params1.length);
    	http.setRequestHeader("Connection", "close");
    	http.onreadystatechange = function()
    	{	
    		if(http.readyState == 4 && http.status == 200)
    		{
    			var results1	=	http.responseText;
    			document.getElementById("id2").innerHTML = results1;
    			//setAndExecute("DIVNAME", results);
    		}
    	}            
    	http.send(params1);
    }
    it shows result of only the function i call second

    can anyone please help me with this!!!
    Last edited by Dormilich; Jan 13 '12, 09:58 PM. Reason: please use [CODE] [/CODE] tags when posting code
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    In the second function, append the result rather than replacing it. Either that or use separate containers. The latter would be my choice.

    Comment

    Working...