PDA

View Full Version : JS Problem with setTimeout



NegroArg
October 22nd, 2008, 12:07 PM
Hi, i need some help with a script i'm trying to make...
I have a php code that gets information from a database, this code is inside a table so the information appears in one cell in particular.

I'm trying to make that cell appear with a delay and i was thinking in using a setTimeout funtion... the thing is that i have no idea on how to get the code done fot that particular cell...
I have this:
<tr id="armonicos">
<td width="25%" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="armonicos">
<caption align="top">
Predominantes
</caption>
<tr>
<td>
<ul>

HERE GOES MY PHP CODE

</ul>
</td>
</tr>
</table></td>

The information inside <ul> </ul> is what I need to delay... can anyone help me?

Thanks very much,

Miguel

actionAction
October 22nd, 2008, 02:24 PM
Just use php



$seconds_to_wait = 3;
sleep($seconds_to_wait);
//process your code

Templarian
October 22nd, 2008, 02:41 PM
^I don't think that's what hes exactly talking about.


<script type="text/javascript">
function doit()
{
document.getElementById('mmm').style.display = 'block';
}
window.setTimeout('doit()', 3000); //3 seconds
</script>


<ul style="display:none;" id="mmm">
<?php echo "php"; ?>
</ul>

NegroArg
October 22nd, 2008, 02:47 PM
Thanks, but if i use PHP the hole page is delayed and not just that small part i need.

The thing is that I need the hole page to load and then the cell to be filled in with the information of the php code... that was hay i wanted to delay the cell and not the hole page...

Any ideas??

NegroArg
October 22nd, 2008, 02:57 PM
^I don't think that's what hes exactly talking about.


<script type="text/javascript">
function doit()
{
document.getElementById('mmm').style.display = 'block';
}
window.setTimeout('doit()', 3000); //3 seconds
</script>


<ul style="display:none;" id="mmm">
<?php echo "php"; ?>
</ul>
That's more that I was looking for... it worked ok selecting that particular cell, now the problem is that it neves charge the script... it just leaves the cell empty... but this script is more what i was looking for

jwilliam
October 22nd, 2008, 02:57 PM
Read Templarian's post. That will work and you may also want to put the setTimeout method in a function and assign it to the window.onload property. Then setTimeout will only fire when the page is completely loaded. For example:



<script type="text/javascript">
function doit()
{
document.getElementById('mmm').style.display = 'block';
}

window.onload = function()
{
window.setTimeout('doit()', 3000); //3 seconds
}
</script>

NegroArg
October 22nd, 2008, 03:03 PM
Read Templarian's post. That will work and you may also want to put the setTimeout method in a function and assign it to the window.onload property. Then setTimeout will only fire when the page is completely loaded. For example:



<script type="text/javascript">
function doit()
{
document.getElementById('mmm').style.display = 'block';
}

window.onload = function()
{
window.setTimeout('doit()', 3000); //3 seconds
}
</script>

Now it works like a Charm... THANKS YOU GUYS!!!

NegroArg
October 22nd, 2008, 03:28 PM
Now it works like a Charm... THANKS YOU GUYS!!!
Man, one last question, if i want to delay some more cells... its ok if i put

<script type="text/javascript">
function doit()
{
document.getElementById('predo').style.display = 'block';
}
window.onload = function()
{
window.setTimeout('doit()', 4000); //4 seconds
}
function doit2()
{
document.getElementById('primer').style.display = 'block';
}
window.onload = function()
{
window.setTimeout('doit()', 6000); //6 seconds
}
</script>
for example?? and I change the id for the different codes?...

jwilliam
October 22nd, 2008, 03:40 PM
You're close, but you can only set the window.onload property once (the second time you set it will override the first). Try this:



<script type="text/javascript">
function doit()
{
document.getElementById('predo').style.display = 'block';
}

function doit2()
{
document.getElementById('primer').style.display = 'block';
}

window.onload = function()
{
window.setTimeout('doit()', 4000); //4 seconds
window.setTimeout('doit2()', 6000); //6 seconds
}
</script>

NegroArg
October 22nd, 2008, 04:19 PM
Great!!, Thanks for all the help