473,324 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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:

Expand|Select|Wrap|Line Numbers
  1. <body onLoad="showContentUsingAJAX();showContext();">
and these are the functions:

Expand|Select|Wrap|Line Numbers
  1. function showContentUsingAJAX()
  2. {
  3.     urlfield            =    "maincategories.php";    //File path which is to be open
  4.     params                =     "pseudoParam="+new Date().getTime();// pseudoparams
  5.     http.open("POST", urlfield, true);
  6.     http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  7.     http.setRequestHeader("Content-length", params.length);
  8.     http.setRequestHeader("Connection", "close");
  9.     http.onreadystatechange = function()
  10.     {    
  11.         if(http.readyState == 4 && http.status == 200)
  12.         {
  13.             var results    =    http.responseText;
  14.             document.getElementById("id1").innerHTML = results;
  15.             //setAndExecute("DIVNAME", results);
  16.         }
  17.     }            
  18.     http.send(params);
  19.  
  20. }
  21. function showContext()
  22. {
  23.     urlfield1            =    "SUBCAT.PHP?catid=1&level=1";    //File path which is to be open
  24.     params1                =     "pseudoParam="+new Date().getTime();// pseudoparams
  25.     http.open("GET", urlfield1, true);
  26.     http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  27.     http.setRequestHeader("Content-length", params1.length);
  28.     http.setRequestHeader("Connection", "close");
  29.     http.onreadystatechange = function()
  30.     {    
  31.         if(http.readyState == 4 && http.status == 200)
  32.         {
  33.             var results1    =    http.responseText;
  34.             document.getElementById("id2").innerHTML = results1;
  35.             //setAndExecute("DIVNAME", results);
  36.         }
  37.     }            
  38.     http.send(params1);
  39. }
it shows result of only the function i call second

can anyone please help me with this!!!
Jan 13 '12 #1
1 2170
Rabbit
12,516 Expert Mod 8TB
In the second function, append the result rather than replacing it. Either that or use separate containers. The latter would be my choice.
Jan 13 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Mike | last post by:
I have some code I am working on. One function reads a file using fso, then I have multiple functions using the string read from the file. Each function splits the lines up and will return one...
5
by: Praveen Srinivasan | last post by:
Hi all, Are there any important issues that one should be aware of when calling C++ functions from C? In particular, I'm passing a function pointer to a C routine in a library, and in that...
7
by: Julia Briggs | last post by:
Hello World - I admit I'm new to javascript but I've tried for days to find a solution to my problem. Basically I have 3 unique javascript files that do different screen display events that I...
10
by: reynoldscraigr | last post by:
Hi All, I am trying to call 2 functions from the 1 onMouseOver event on an anchor tag, but I can't seem to get it to work. the following should demonstrate <a...
19
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const...
13
LacrosseB0ss
by: LacrosseB0ss | last post by:
I was wondering, can an OnClick event of a button call multiple functions? The reason for this is I have a page that when "ok" is clicked, goes to a preview page before submitting data to the...
8
by: nkoriginal | last post by:
Hi: (this is a dummy question, I know, but I tried many times and I cant) I need to insert this javascript option inside the input, I can't insert any funtion in <head> I've this two...
1
by: jobs | last post by:
re: Attributes.Add Onclick (javascript) trapping CANCEL Hello. The following asp.net/vb.net code produces a confirmation Submitbutton.Attributes.Add("onClick", "return confirm('Is this...
3
by: nigelesquire | last post by:
Please help! I'm trying to clone and delete multiple rows with JavaScript. I need two delete buttons that work...! I only have one for now, but it's not working properly, the output count is...
1
by: su817200 | last post by:
Dear Friend, I would like to run multiple functions on Button Click eg... <input type="button" value="Update" name="B1" onclick="ReadFileToString() timedRefresh(1500)"></p> It is giving...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.