views:

399

answers:

3

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

<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>



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

Elements with IDs "div1" and "div2" probably does not exists, which causes an error in the function -> function not declared.

Itay Moav
But that error won't be like 'function not defined'.
rahul
A: 

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">
levik
+2  A: 

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 cdoe
        document.getElementById("favSports").style.visibility="visible";
       // corrected code
    }
}
rahul