Jump to content

setTimeout syntax problem


gareth2

Recommended Posts

could some one tell me what is wrong with this.
[code]<p align=center id=message_0 

style=visibility:hidden>You attack $stat1[user] for

$stat[att].</p>
<script>
var message_0 = 

document.getElementById(message_0);
window.setTimeout(message_0.style.visibility='visib

le', 100);</script>[/code]
Link to comment
https://forums.phpfreaks.com/topic/31514-settimeout-syntax-problem/
Share on other sites

I am by no means and expert, so take this with a grain of salt, but on the HTML side of things "align" is a deprecated attribute with regard to the <p> tags. You also should have id="message_0" and style="visibility:hidden" (if your intention is for the latter to be a CSS style).
darrin365 is on the right track. Your main issue is that within your getElementById() function call, you must have the id name within quotes. In addition, you really need to clean up your markup, or you'll have all sorts of issues in the long run. Also, your setTimeout function accepts a [b]string[/b] as the first parameter, not straight code. So, you need to either write a function that will show what you're after, and call that function, or you need to encapsulate your script to run within quotes:
[code]
<p align="center" id="message_0 " style="visibility:hidden;">
You attack $stat1[user] for $stat[att].
</p>

<script type="text/javascript">
function showDiv(id) {
  var myDiv = document.getElementById(id);
  myDiv.style.visibility = 'visible';
}

window.setTimeout('showDiv("message_0")', 100);
</script>
[/code]

Good luck.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.