PDA

View Full Version : Random show one layer or another



jmooring
Mar 17th, 2007, 05:52 PM
I'd like to have a couple (or perhaps three) layers on a page that are hidden. Upon opening the page, just one of these layers randomly shows itself. Would that be done with an array of some kind? Any specifics would help... Thx!

Mr J
Mar 17th, 2007, 06:34 PM
Here's a couple of basic examples


<HTML>
<HEAD>
<TITLE>Document Title</TITLE>


<script type="text/javascript">

onload=function showDiv(){
rdmNum=Math.floor(Math.random()*3)
document.getElementById("d"+rdmNum).className="isvisible"
}

</script>


<style type="text/css">

.ishidden{
display:none;
}

.isvisible{
display:block;
}


</style>
</HEAD>
<BODY>

<div id="d0" class="ishidden">Hidden One</div>
<div id="d1" class="ishidden">Hidden Two</div>
<div id="d2" class="ishidden">Hidden Three</div>

</BODY>
</HTML>



<HTML>
<HEAD>
<TITLE>Document Title</TITLE>


<script type="text/javascript">

arr=[
"Contents for the div are coded into an array",
"The contents of the div are then randomly changed",
"Have a nice day"

]

onload=function showDiv(){
rdmNum=Math.floor(Math.random()*3)
document.getElementById("d0").innerHTML=arr[rdmNum]
}

</script>

</HEAD>
<BODY>

<div id="d0"></div>

</BODY>
</HTML>

jmooring
Mar 19th, 2007, 06:19 AM
Really appreciate the help. That seems to do the trick!