0

This is a very strange thing. I have a custom.js file with functions and listeners needed in some views. The listeners work fine in the views as the custom.js in called in the header. But the functions do not seem to work. I get an error "Uncaught ReferenceError: someFunction is not defined". I checkedc and checked if the spelling of the function name is correct and that's not it, it seems. But I find it very strange as the javascript file is parsed correctly as the listeners work.

Please can somebody please help me here

custom.js

$(document).ready(function () {
    var someFunction = function() {
        //do something
    }
});

Header of default.ctp

<script src="/js/custom.js"></script>

Call to a function in a view

<script type="text/javascript">
    someFunction();
</script>

Nothing seems wrong to me. Looks like a straight forward thing. So wondering if this is a typical cakePHP thing

Alvin Bakker
  • 1,456
  • 21
  • 40
  • In other words, there's no reason to define functions inside document ready. – JJJ Jul 01 '14 at 20:11
  • what do you want to do clearly, in order to give you some options...or guide you with your problem...what could do your function?? – MickyScion Jul 01 '14 at 20:19
  • 1
    Jeez, how stupid of me. Of course that's the case. I really must have been thinking in a loop hole :( Thanx guys – Alvin Bakker Jul 01 '14 at 21:51

0 Answers0