Results 1 to 3 of 3

Thread: Script Not Working in IE

  1. #1
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default Script Not Working in IE

    I have menus for a restaurant. Each "page" is a transparent gif that displays over a constant background. With JavaScript, I have those gif's change when someone clicks on a page number. The "pages" change perfectly in every browser but IE, even 8. Why?

    Here's an example, the Lunch menu: http://vittoriosbuonappetito.com/ind...enu&menu=lunch

    Here is the HTML for the menu:
    HTML Code:
    		<div id="menu_submenu">
    			<span>
    				Page: 
    				<a href="#" onclick="changeMenu('lunch',1)" id="one" class="sbover">1</a> . 
    				<a href="#" onclick="changeMenu('lunch',2)" id="two">2</a> . 
    				<a href="#" onclick="changeMenu('lunch',3)" id="three">3</a> .
    				<a href="printMenu.php?menu=lunch" target="_blank">Print</a>
    			</span>
    		</div>
    		
    		<div id="menu_container" class="lunch">
    			<div id="luntitle"></div>
    			<div id="luncont">
    				<div id="lc" class="lc1"></div>
    			</div>
    			<div id="menu_bot" class="lp1"></div>
    		</div>
    The following is the JavaScript:
    Code:
    function changeMenu(menu,number){
    	if(menu == "lunch"){
    		c = "lc";
    		p = "lp";}
    	else if(menu == "dinner"){
    		c = "dc";
    		p = "dp";}
    	else if(menu == "cater"){
    		c = "cc";
    		p = "cp";}
    	cont = document.getElementById(c);
    	pageImg = document.getElementById('menu_bot');
    	link1 = document.getElementById('one');
    	link2 = document.getElementById('two');
    	link3 = document.getElementById('three');
    	if(number == 1){
    		link1.className="sbover";
    		link2.className="";
    		link3.className="";
    	}
    	else if(number == 2){
    		link1.className="";
    		link2.className="sbover";
    		link3.className="";
    	}
    	else if(number == 3){
    		link1.className="";
    		link2.className="";
    		link3.className="sbover";
    	}
    	else{
    		number=1; 
    		link1.className="sbhover";
    		link2.className="";
    		link3.className="";
    	}
    	cont.className=c+number;
    	pageImg.className=p+number;
    }
    Last edited by alexjewell; 06-27-2010 at 02:20 AM.
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  2. #2
    Join Date
    Oct 2009
    Posts
    845
    Thanks
    14
    Thanked 189 Times in 188 Posts

    Default

    I'm just playing around without really understanding much of it, but there's a javascript error in IE relating to the Id 'cont'. Can you rename this id <div id="cont"> without ruining everything ?

  3. #3
    Join Date
    Jul 2008
    Posts
    128
    Thanks
    0
    Thanked 17 Times in 16 Posts

    Default

    Quote Originally Posted by alexjewell View Post
    I have menus for a restaurant. Each "page" is a transparent gif that displays over a constant background. With JavaScript, I have those gif's change when someone clicks on a page number. The "pages" change perfectly in every browser but IE, even 8. Why?
    It's the common mistake of creating global variables (which you don't need) whose name conflicts with an ID. When you declare a variable inside a function, use the var keyword.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •