Aaron
Aaron

Reputation:

Function not defined javascript

For some reason my javascript code is messed up. When run through firebug, I get the error proceedToSecond not defined, but it is defined!

JavaScript:

<script type = "text/javascript">
    function proceedToSecond () {
        document.getElementById("div1").style.visibility="hidden";
        document.getElementById("div2").style.visibility="visible";
    }

    function reset_Form() {
        document.personalInfo.reset();
    }

    function showList() {
        alert("hey");
        if (document.getElementsById("favSports").style.visibility=="hidden") {
            document.getElementsById("favSports").style.visibility="visible");
        }
    }

    //function showList2() {
    //}
</script>

HTML:

<body>
    <!--various code -->
    <input type="button" onClick="proceedToSecond()" value="Proceed to second form"/>
</body>

Upvotes: 13

Views: 146788

Answers (4)

amiri89
amiri89

Reputation: 11

important: in this kind of error you should look for simple mistakes in most cases

besides syntax error, I should say once I had same problem and it was because of bad name I have chosen for function. I have never searched for the reason but I remember that I copied another function and change it to use. I add "1" after the name to changed the function name and I got this error.

Upvotes: 1

I just went through the same problem. And found out once you have a syntax or any type of error in you javascript, the whole file don't get loaded so you cannot use any of the other functions at all.

Upvotes: 1

rahul
rahul

Reputation: 187030

The actual problem is with your

showList function.

There is an extra ')' after 'visible'.

Remove that and it will work fine.

function showList()
{
  if (document.getElementById("favSports").style.visibility == "hidden") 
    {
       // document.getElementById("favSports").style.visibility = "visible");  
       // your code
       document.getElementById("favSports").style.visibility = "visible";
       // corrected code
    }
}

Upvotes: 29

levik
levik

Reputation: 117499

There are a couple of things to check:

  • In FireBug, see if there are any loading errors that would indicate that your script is badly formatted and the functions do not get registered.
  • You can also try typing "proceedToSecond" into the FireBug console to see if the function gets defined
  • One thing you may try is removing the space around the @type attribute to the script tag: it should be <script type="text/javascript"> instead of <script type = "text/javascript">

Upvotes: 4

Related Questions