"Uncaught TypeError: object is not a function" when calling a function

14,617

In the Chrome browser you can ask that JS execution stops at an exception. To enable that, open the JS console and click on the small icon to the left of the moustaches between the main panel and the console. If the icon is blue you will stop execution on all exceptions, if red only on uncaught exceptions and if it is gray no stop at all.

So click until it is red to stop on uncaught exceptions. Run your web-page and executon should stop EXACTLY at the point the exception is raised. Then you can examine the value of the validate variable.

I suspect it is some sort of global varaible clash between your code and other code you are loading. To check that quickly, rename validate something like QQvalidate and try your code.

Share:
14,617
Joshua
Author by

Joshua

Web Application Developer specialising in WordPress and Magento.

Updated on June 04, 2022

Comments

  • Joshua
    Joshua almost 2 years

    I am having this odd error with my code. I am trying to troubleshoot a page that [used] to work in Chrome but not in IE (suprise suprise) by adding specific triggers but now I am getting the Uncaught TypeError: object is not a function error in Chrome's console.

    As far as I can tell this is a function (work in progress):

    <script type="text/javascript">
        function validate() {                
                var id = jQuery("form").attr('id');
                var formid = "#"+id;
                jQuery(formid).add("<input type=\"hidden\" name=\"APC_UPLOAD_PROGRESS\" value=\""+id+"\" />");
                jQuery("#validate").hide();
                jQuery("#submitme").show();
        }
    </script>
    

    It is being called by the following code:

    <button id="validate" onClick="validate()" type="button">Validate</button>
    

    I am not using <input type="submit> as I have extra form submit JS to run.

    So when I click the button the page does nothing and I get titular said error in the console.

    I have tried using jQuery.fn.validate = function(){}; but to no avail.

    To make this more interesting, the site is Wordpress and this particular page loads jQuery and MooTools as well as have straight JS.

    In a nutshell; what silly little mistake have I made? All the searches on google are years old and generated by what I assume to be classes.

    UPDATE

    The console says this line is the error

    <button id="validate" onClick="validate()" type="button">Validate</button>
    

    UPDATE 2

    Pastbin link to the form code http://pastebin.com/3Kw5vdhn