efc_90
10 Jan 2011, 07:55 AM
--------------------------------------------------------------------------------
Hi all,
I have a problem where I'm trying to load data into multiple divs. They are payslips, so p1, goes into january, p2 into febuary etc. I want to onLoad them all so when the page is loaded they are all displayed.
Every time I try this, the loop automatically goes to the last iteration, 6 in this example, so the only div that is loaded is p6.
Here is my code:
function replace(slip, year) {
xmlHttpReq.open("POST", "do_payslips_ajax.php", true);
xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttpReq.onreadystatechange=function() {
if(xmlHttpReq.readyState == 4) {
document.getElementById("p" + slip).innerHTML = xmlHttpReq.responseText;
}
}
xmlHttpReq.send(getquery(slip,year));
}
function getquery(slip,year) {
strQuery = "weekmonth=" + slip + "." + year;
return strQuery;
}
function loadpayslips(year) {
for (slip=1; slip<=6; slip++) {
replace(slip, year);
}
}
<label>
<body onload = loadpayslips(11)> search</a>
</label>
<div id="p1">
/div>
<div id="p2">
month 2</div>
<div id="p3">
month 5</div>
etc..
Any help would be appreciated.
Thanks
Hi all,
I have a problem where I'm trying to load data into multiple divs. They are payslips, so p1, goes into january, p2 into febuary etc. I want to onLoad them all so when the page is loaded they are all displayed.
Every time I try this, the loop automatically goes to the last iteration, 6 in this example, so the only div that is loaded is p6.
Here is my code:
function replace(slip, year) {
xmlHttpReq.open("POST", "do_payslips_ajax.php", true);
xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttpReq.onreadystatechange=function() {
if(xmlHttpReq.readyState == 4) {
document.getElementById("p" + slip).innerHTML = xmlHttpReq.responseText;
}
}
xmlHttpReq.send(getquery(slip,year));
}
function getquery(slip,year) {
strQuery = "weekmonth=" + slip + "." + year;
return strQuery;
}
function loadpayslips(year) {
for (slip=1; slip<=6; slip++) {
replace(slip, year);
}
}
<label>
<body onload = loadpayslips(11)> search</a>
</label>
<div id="p1">
/div>
<div id="p2">
month 2</div>
<div id="p3">
month 5</div>
etc..
Any help would be appreciated.
Thanks