Forum Moderators: open

Message Too Old, No Replies

change DIV

         

moiseszaragoza

5:22 pm on Mar 14, 2007 (gmt 0)

10+ Year Member



Ok this is what i am trying to do.

I have a timer. and after 1 sec i want display a div.

my code:

<script type="text/javascript">
<!--
function delay(){
alert("New var")
document.div.Temp1.style=""
// At this time i need to we need to show the content of the div

}
//-->
</script>

<body onLoad="setTimeout('delay()', 1000)">
<!-- calls the JavaScrip Junction (Works) -->

<div id="Temp1" style="display:none">
#*$!#*$!#*$!#*$!X
</div>

ericjust

5:30 pm on Mar 14, 2007 (gmt 0)

10+ Year Member



<script type="text/javascript">
<!--
function delay(){
// alert("New var");
document.getElementById("Temp1").style.display = "";
}
//-->
</script>

Fotiman

5:36 pm on Mar 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



1. Welcome!
2. You don't need the <!-- --> in your script blocks (you should remove them).
3. document.div.Temp1.style - document.div does not exist, so therefore neither does document.div.Temp1. Also, you need to specify a property of style to set... in this case, you should be setting display to block.
4. You should use DOM methods to get the element you want to modify (in this case, you should use document.getElementById).
5. You should consider keeping your JavaScript separate from your HTML... that is, avoid using attributes like "onLoad", and instead "attach" the handlers via JavaScript.

Below is your corrected code:


<body>
<div id="Temp1" style="display:none">
#*$!#*$!#*$!#*$!X
</div>
<script type="text/javascript">
function delay(){
alert("New var")
var Temp1 = document.getElementById("Temp1");
// At this time i need to we need to show the content of the div
Temp1.style.display="block";
}
window.onload = function(){
setTimeout(delay, 1000);
}
</script>
</body>

[edited by: Fotiman at 5:36 pm (utc) on Mar. 14, 2007]