Connecting Tech Pros Worldwide Forums | Help | Site Map

Firefox won't work with show/hide div script

Newbie
 
Join Date: Mar 2007
Posts: 1
#1: Mar 5 '07
This code works fine in IE, but doesn't do anything in Firefox. Is there an issue with the layer_ref?
If you could re-write this to make it work, I would love you for it!
Expand|Select|Wrap|Line Numbers
  1. <!-- Start Show / Hide Div Script -->
  2. <script language="javascript">
  3.         <!--
  4.         var state = 'none';
  5.  
  6.         function showhide(layer_ref) {
  7.  
  8.         if (state == 'block') {
  9.         state = 'none';
  10.         }
  11.         else {
  12.         state = 'block';
  13.         }
  14.         if (document.all) { //IS IE 4 or 5 (or 6 beta)
  15.         eval( "document.all." + layer_ref + ".style.display = state");
  16.         }
  17.         if (document.layers) { //IS NETSCAPE 4 or below
  18.         document.layers[layer_ref].display == state;
  19.         }
  20.         if (document.getElementById && !document.all) {
  21.         maxwell_smart = document.getElementById(layer_ref);
  22.         maxwell_smart.style.display == state;
  23.         }
  24.         }
  25.         //-->
  26. </script>
  27. <!-- End Show / Hide Div Script -->
  28.  
iam_clint's Avatar
Forum Leader
 
Join Date: Jul 2006
Location: Oklahoma
Posts: 1,076
#2: Mar 5 '07

re: Firefox won't work with show/hide div script


document.all (not supported by most browsers)

use document.getElementById()
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#3: Mar 5 '07

re: Firefox won't work with show/hide div script


Also, the line
Expand|Select|Wrap|Line Numbers
  1. maxwell_smart.style.display == state;
should be
Expand|Select|Wrap|Line Numbers
  1. maxwell_smart.style.display = state;
You are comparing instead of setting.
sumittyagi's Avatar
Expert
 
Join Date: Mar 2007
Location: New Delhi, India
Posts: 198
#4: Mar 6 '07

re: Firefox won't work with show/hide div script


also:
eval( "document.all." + layer_ref + ".style.display = state");

should be:
eval("document.all." + layer_ref + ".style.display = " + state);

//but use document.getElementById(layer_ref).style.display = state; instead

//document.all is supported in firefox, but it is depricated, i.e. a warning message is shown.
but document.getElementById is supported in almost all the browsers.
Reply