SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard dethfire's Avatar
    Join Date
    Aug 2000
    Posts
    2,477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    function just not working

    i get two error, one says formal parameter is missing and that switchmenu is undefined, I don't get it!?

    Code:
    <script type="text/javascript">
    
    function switchmenu(goto)
    {
    
    var current = document.GetElementById("placeholder");
    current.style.visibility = "hidden";
    document.goto.style.visibility = "visible";
    current.value = goto;
    
    }
    
    </script>
    
    </head>
    <body>
    
    <input type="hidden" value="norsemenu" name="placeholder">
    
    <div id="top">
    <img src="logo.gif">
    </div>
    
    <div id="menu">
    <ul>
    <li><a href="#" onclick="switchmenu('greekmenu');">Greek</a></li>
    <li><a href="#" onclick="switchmenu('norsemenu');">Norse</a></li>
    <li><a href="">Eygptian</a></li>
    <li><a href="">African</a></li>
    <li><a href="">Celtic</a></li>
    <li><a href="">Chinese</a></li>
    </ul>
    </div>
    Free Science Homework Help
    http://www.physicsforums.com

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You must be a VB coder -- the camel-casing in JS is lower camelCase, not upper CamelCase.

    document.getElementById()

    Also, I must ask: Why are you enacting a fuction that hides an item (via style) that is already hidden (via the type attribute)?
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Guru bronze trophy blufive's Avatar
    Join Date
    Mar 2002
    Location
    Manchester, UK
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    function switchmenu(goto)
       {
        var current = document.GetElementById("placeholder");
        current.style.visibility = "hidden";
        document.goto.style.visibility = "visible";
        current.value = goto;
       }
    A few other things, besides what Beetle pointed out:


    1. "goto" is a reserved word in javascript - you can't use it as a variable name
    2. you're attempting to use document.all to set the visibility, which won't work in many non-IE browsers
    3. You're actually selecting an element named "goto", which doesn't exist.
    So:
    Code:
    function switchmenu(target)
       {
        var current = document.getElementById("placeholder");
        current.style.visibility = "hidden";
         document.getElementById(target).style.visibility = "visible";
        current.value = target;
       }
    However, following on from Beetle's second question, I suspect that you're confused about how variables/variable names work, and what what you actually want is this:
    Code:
    function switchmenu(target)
        {
         var current = document.getElementById("placeholder");
         document.getElementById(current.value).style.visibility = "hidden";
          document.getElementById(target).style.visibility = "visible";
         current.value = target;
        }
    [none of this has been tested, so no promises]


    offtopic:
    has anyone else found that code blocks do really funky things with indentation these days?


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
  •