SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What's wrong with this code?

    This script isn't working like it should and I'm not sure why. I'm new to Javascript programming so the obvious won't be so obvious to me. When I run the script thru the IE debugger, the variable "mnuItm" does contain one ofthe values in the case clause but it's not taking that path. It takes the "Default" path when it shouldn't.

    I also tried using the "id" as the switch object and that worked. I have no idea why one works and the other doesn't. Please help!

    Thanks,

    Blake

    Code:
    	function NoFunctionality(id)
    	{
      		var blnRedirect = true;
    			
    		mnuItm = document.getElementById(id).innerText;	*/
    				
    		switch ( mnuItm ) 
    		{
    			case 'liPhase1':
    				alert("Phase 1 functionality is not yet implemented!");						
    				blnRedirect = false;
    				break;
    			case 'liPhase2':
    				alert("Phase 2 functionality is not yet implemented!");
    				blnRedirect = false;
    				break;
    			case 'liPhase3':
    				alert("Phase 3 functionality is not yet implemented!");
    				blnRedirect = false;
    				break;
    			case 'liPhase4':
    				alert("'Phase 4 functionality is not yet implemented!");
    				blnRedirect = false;
    				break;
    			default:
    				alert("Unknown Selection!");
    				break;
    		}
    	}

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    Well, first take out */.

    Everything else looks okay though. You just need to make sure that the id value you are passing in is valid.

    Also, try adding "alert(mnuItm)" before the switch and visually see if the value you are getting is one of your options.

  3. #3
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Removing the */ didn't help. However, when I did the alert on the mnuItm, it still showed the correct value which should have been reflected in the Switch statement.

  4. #4
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    Select the text in the alert and see if it has any random spaces or anything in there.

  5. #5
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Be aware that innerText is not globally supported and should not be used on the web.
    Tab-indentation is a crime against humanity.


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
  •