user3871
user3871

Reputation: 12664

Object undefined on click

I'm trying to call a member function of my Utilities object on button click. The js file containing the object is loaded at the top of the index.php page:

<script type="text/javascript" src="js/utilities.js"></script>
...

And have defined the button:

<button id="testAJAX" onclick="Utilties.loadSavedGames()">Load Game</button>

When I click, I get Utilties is not defined error:

var Utilities = {
     loadSavedGames : function () {
        console.log("Clicked"); //returns Utilties is not defined
     },...

But I'm curious why if I reload the page, it's able to call the anon function. This tells me that the Utilties object is clearly being loaded at page load:

var Utilities = {
    doThis : (function() {
        console.log("Utilities object loaded"); //runs just fine
    })(),

So if the object is loaded at top of index.php page, why would onclick tell me the object is undefined?

Upvotes: 0

Views: 132

Answers (1)

Jesse Kernaghan
Jesse Kernaghan

Reputation: 4634

In your javascript you are setting Utilities, but your onclick is referencing Utilties. Missing an i.

Upvotes: 2

Related Questions