PHP->JS (Automatically scroll down)

Hi,
I think you might need a little PHP knowledge here...but either way its quite easy to understand.

This is what I have in my php script

for($i=100;$i>=0;$i--)
{
if($i==0 )
{echo "<h1>BOOM!</h1>";}
else{echo "counting down".$i."<br>";}
echo str_repeat(" ", 256);   flush();   ob_flush();
sleep(1);
}

Basically what it does is, it prints out "counting down <x>" where x is a number like this:
 
counting down 99
counting down 98
counting down 97
etc

till it reaches 0 then it displays "Boom!"
I have also used the "sleep" function so it does not go too fast but shows the "counting down message" every second.

My problem is when it displays the message it does not scroll down...so the user only sees the top half of the page while the "countdown" is still loading below.
Is there any way for this to follow the ouput at the bottom of the page?

I dont know JavaScript too well but I see there are lots of JS gurus here...I'm pretty sure this wont be too tough for ya, sorry I cannot offer more points but thats all that available in my account (I will give an A to the person who solves this though), the points for the people I have helped I cannot seem to touch :-( otherwise i would have offered more to you guys..
but maybe i can make it up to you in future by helping you in some php problem :-)

Thanks,
Mag
LVL 2
mag1c1anAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ZvonkoConnect With a Mentor Systems architectCommented:
Thanks for the php offer ;-)

Check this:
echo str_repeat(" ", 256)."<script>window.scrollTo(0,9000)</script";   flush();   ob_flush();

0
 
mag1c1anAuthor Commented:
Hey,
I was right....there are JS gurus here!

Works like a charm! Thanks.

As far as I am concerned the points are yours and this is closed, but before I award you the points I have a question about some odd behevior (you get the points if you answer this or not, i just dont know if after I award you the points this will be "open" or "locked")

In Opera I get to see the *second last* line and not the last line...the last line is covered up with the loading bar, any way to take that out so I see the last line?

Cheers,
-Mag
0
 
mag1c1anAuthor Commented:
P.S your ending <script> tag was open... :-)
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
ZvonkoSystems architectCommented:
Uhps, sorry :)

0
 
ZvonkoSystems architectCommented:
Is the last line missing also with the correct script end tag?
0
 
ZvonkoSystems architectCommented:
How about this:

echo "<div id='msg' style='color:red;'></div><br><br><br>";
for($i=100;$i>=0;$i--){
  if($i==0 ) {
     $msgText = "<h1>BOOM!</h1>";
  }else{
     $msgText = "counting down".$i."<br>";
  }
  echo "<script>document.getElementById('msg')='".$msgText."'</script>";
  echo str_repeat(" ", 256);  
  flush();  
  ob_flush();
  sleep(1);
}



0
 
ZvonkoSystems architectCommented:
I was not sure if this var is evaluated:
   echo "<script>document.getElementById('msg')='$msgText'</script>";

0
 
mag1c1anAuthor Commented:
Hi,
Nah, forget it, it seems that that "feature" is built into Opera. It works great on IE and NN so am happy.

Thanks.
Mag
0
 
ZvonkoSystems architectCommented:
Thanks for points.
0
All Courses

From novice to tech pro — start learning today.