By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,959 Members | 1,139 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,959 IT Pros & Developers. It's quick & easy.

Javascript working in firefox but not IE

P: 1
This script seems to work fine with firefox but not with IE. It just sets style="display:none" or style="display:" to show / hide submenu items on my menu. I've just tried making it save to a cookie which submenu is currently displayed and reopen that menu on a new page load.

checkCookie() is called onload and switchMenu(menuidhere) when the main menu item is clicked to make the submenu appear. Firefox doesn't display any js errors and reopens the correct menu on a page load whereas IE throws an "object required" error.


Expand|Select|Wrap|Line Numbers
  1. function switchMenu(obj) {
  2. var hid = "hide";
  3.     var el = document.getElementById(obj);
  4.     if ( el.style.display != "none" ) {
  5.         el.style.display = 'none';    
  6.         setCookie(hid,1);                
  7.     }
  8.     else {
  9.         el.style.display = '';    
  10.         setCookie(obj,1);    
  11.     }
  12. }
  13.  
  14.  
  15. function setCookie(menuid,expire)
  16. {
  17. var c = "menuid=" + escape(menuid) + ";expires=" + escape(expire);
  18.  //write cookie
  19. document.cookie = c;
  20. }
  21.  
  22. function checkCookie()
  23. {      
  24.  openmenu = getCookie('menuid'); 
  25. if (openmenu != 'hide') {  
  26.    switchMenu(openmenu);   //problem appears to be this line
  27.    }    
  28.    else { switchMenu("hide"); }
  29. }
  30.  
  31.  
  32.  
  33. function getCookie(cookieName) {
  34.  var theCookie=""+document.cookie;
  35.  var ind=theCookie.indexOf(cookieName);
  36.  if (ind==-1 || cookieName=="") return ""; 
  37.  var ind1=theCookie.indexOf(';',ind);
  38.  if (ind1==-1) ind1=theCookie.length; 
  39.  return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
  40. }
Nov 9 '07 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
Can you also show the menu code.

Is the ID "hide"?
Nov 9 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.