ZoomCities IT Community Webmaster Forum

Full Version: Javascript: real time write to divs?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a javascript that writes to a grid of divs. There are several loops through which it iterates to get the data it needs for each div, so it may take as long as 15 seconds to reach completion.

I've noticed that anything written to window.status appears immediately but that nothing is written to any div until the very end and then everything appears.

My question: is there some setting that defaults to this "wait until the end before you actually write anything"--do I have an option to change it so the divs could be filled as soon the program reached the line telling it to write to the div?

I'm using

document.getElementById("somelabelname" + i).innerHTML += "the text to write into the div ends up here..."

Thank you for your help with this.

-Larry
that line shud work fine and i've done something very similar before in an ajax adding email addresses to a database from a massive list.

if you show the loop it might be easier to see where you are going wrong.
There isn't any problem with the code. It's working fine and the calculations are correct. I'll show a nested loops example though, per your request.

I am anticipating one of two answers:

1)it can't be done--Javascript can't write to divs in real time
2)it can be done and there is some code or trick I need to use in order to make it happen.

Example code:

for (i = 1; i <= formulationlinescount; i++)
{
if (FormulationFL[i] == dropdownchoice)
{
for (j = 1; j <= materialscount; j++)
{
if (Material[j] == MaterialFL[i])
{
lbstotal += lbsFL[i] * 1;
galtotal += lbsFL[i] / density[j];
costtotal += lbsFL[i] * price[j];
}
}
}
}
one of you loops with the .innerHTML was what i was looking for Wink

remember you need to be setting the div content inside the loop for it to appear as it runs that part of the loop.
I see what you are saying.

However, there are 5 subroutines now (and more planned) and each subroutine could go through as many as 16 other iterations. I'll try to illustrate it (without taking up 200 lines here) : - )

Subroutine 1
f loop (1 to 16)
.i loop (1 to 3000)
..j loop (1 to 400)
at one point a something[i]/something[j] condition is met
several lines written
..end j loop
.end i loop
end f loop

//by the time this is complete 16 different divs have info

Subroutine 2
f loop (1 to 16)
.i loop (1 to 3000)
..j loop (1 to 400)
...k loop (1 to 300)
at one point a something[i]/something[j] condition is met
several lines written
...end k loop
..end j loop
.end i loop
end f loop

//by the time this is complete 16 different divs have info

This is done for three more subroutines and I may be adding more subroutines.

Since previously you only saw one subroutine it makes sense that my placement of the write statement at the end would be the cause of the writing happening only at the end. I hope that the above explanation showing the multiple loops helps to clear this up.

Thank you for your interest in solving this. I still think that if the answer exists it will need to be an explicit command that tells Javascript to change from "publish at the end mode" to "publish in real time mode".

-Larry
hmm, i'm pretty convinced that the answer dosn't come from a switch to change that mode as javascript is an interactive language so should give results imediatly.

honestly if you can post the code or link us to an example of it in action it would help a lot, theres a lot of experts here we wont get scared off by even a thousand lines of code because most of us have written to that extent many times before
Reference URL's