Forum Moderators: open

Message Too Old, No Replies

show/hide javascript works in firefox/safari but not ie

         

trapezechic

4:08 am on Apr 10, 2010 (gmt 0)

10+ Year Member



I'm using this script to show hide elements on the page. It works perfectly in Firefox & Safari. IE does not recognize it. Any ideas?

<script type="text/javascript">
lastone='empty';
function showIt(lyr)
{
if (lastone!='empty') lastone.style.display='none';
lastone=document.getElementById(lyr);
lastone.style.display='block';
}
</script>
</head>

<body>
<table cellspacing="20">
<tr>
<th colspan="6" class="size">Where would you like to start?</th>
</tr>
<tr>
<td><a href="JavaScript:;" onClick="showIt('L')" "><img src="../images/icon-live.jpg" width="100" height="100" /></a><br /><span class="room">Live</span></td>
<td><a href="JavaScript:;" onClick="showIt('E')" "><img src="../images/icon-eat.jpg" width="100" height="100" /></a><br /><span class="room">Eat</span></td>
<td><a href="JavaScript:;" onClick="showIt('W')" "><img src="../images/icon-work.jpg" width="100" height="100" /></a><br /><span class="room">Work</span></td>
<td><a href="JavaScript:;" onClick="showIt('S')" "><img src="../images/icon-sleep.jpg" width="100" height="100" /></a><br /><span class="room">Sleep</span></td>
<td><a href="JavaScript:;" onClick="showIt('C')" "><img src="../images/icon-cook.jpg" width="100" height="100" /></a><br /><span class="room">Cook</span></td>
<td><a href="JavaScript:;" onClick="showIt('B')" "><img src="../images/icon-bath.jpg" width="100" height="100" /></a><br /><span class="room">Bath</span></td>
</tr>

daveVk

12:50 am on Apr 11, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<a href="JavaScript:;" onClick="showIt('L')" ">

extra qoute may be issue, validating your html will save you a lot of time.

Other changes I would make

<script type="text/javascript">
var lastone='empty';
function showIt(lyr) {
if (lastone!='empty') lastone.style.display='none';
lastone=document.getElementById(lyr);
lastone.style.display=''; // does not reply on it being a block
return false;

}

change links to

<a href="#" onClick="return showIt('L');">..

trapezechic

3:02 am on Apr 11, 2010 (gmt 0)

10+ Year Member



Fabulous! Thanks!