can't call this function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aashishn86
    New Member
    • Mar 2009
    • 51

    can't call this function

    Code:
    <html>
    <head>
    <script type="text/javascript">
    
    var flag=0;
     
    callf()
     {
      if(flag == 0)
       {
        test()
         {
           alert("hi from if");
         }
       }
    
    else
      {
        alert("hi from else");
      }
     }
    
    
    
    </script>
    
    </head>
    <body>
    
     <input type="text" onchange="callf();">
    
    </body>
    </html>
    what's wrong with this code ??
    nothing happens when i type into the text box..
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by aashishn86
    what's wrong with this code ??
    check out the Error Console!

    callf() is not a function. functions are defined using the function keyword.

    Code:
    function callf() { // code comes here }
    
    // alternatively
    var callf = function() { // code comes here }

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Two other problems:
      1. test() is not defined.
      2. It's called onchange, so it won't fire on key presses, but after the field loses focus and there's been a change.

      Comment

      Working...