How can i call two functions with body onLoad event? Suppose i would like to call two ajax functions to load default data with abc() and xyz() functions in my onLoad event of body. I have done simple as calling two functions like this:
Code:
I’m curious, why do you want to call AJAX functions via onload?
Using body’s inline onload attribute is bad practice. Using inline event handlers on other elements is not best practice, because it’s best to put all JavaScript, including events, in external .js files. It’s even worse to use them on <body> because they will overwrite any events for window defined in other JavaScript code blocks.
Thank you very much Kravvitz for concerning on my post. Actually i am not perfect in AJAX even though i have used a few functions (created by myself). I have used <body> onload event to call the function and load the default data in my div. So i want to populate two divs with default data when the page gets loaded.
This is the almost all code and there is another file actionfile.php which will be loaded in the div idied ContentOne. Likewise i want to load another file in another div ContentTwo in the page load.
I think you can see there is a form to select the date ranges and click on the Go button, it will call that file again with records that are in that date range whereas the on the onload call it will show all the records.
I think including the pages is not the ajax. Is this? Then how can i pass pid and selected date ranges to that file without refreshing the whole page?
I think you can see there is a form to select the date ranges and click on the Go button, it will call that file again with records that are in that date range whereas the on the onload call it will show all the records.
It would be worth spending some time researching events. Using inline scripting works, but it makes your code messy and difficult to maintain. If you put code in an external JS file, you can use:
function PageLoad() {
function1(); function2(); functionN();
}
window.onload = PageLoad; // no parenthesis after function name
Alternatively, you could use window.addEventListener (or window.attachEvent in IE6 and below). This allows you to add more than one event handler, but you cannot guarantee which order event handlers will be fired.
It may be worth looking at the event handlers in some of the many script libraries (Yahoo, scriptalious, etc). But, it’s always worth writing your own to get a good understanding of browser events.