Skip to content Skip to sidebar Skip to footer

Setting A Variable To A String Returning As Null

I have These Variables at the moment var rsCash = 0; var rsCashString = rsCash.toString(); var rsCashLength = rsCashString.length; I am using the rsCash Variable in a Switch State

Solution 1:

The error is pointing you to this code (repeated many times):

document.getElementById("cash3").innerHTML = rsCash + "Gp";

The document.getElementById("cash3") call is returning null here. You need to properly find your element.

You probably only need to do this:

var cashElement = document.getElementById("correctID");

Then reuse that variable throughout.

Like commenters have said, it's likely that this is because you are executing the code before the DOM is loaded. jQuery has simple ways to handle this by placing code in $(document).ready, or it can be done in vanilla javascript:

document.addEventListener("DOMContentLoaded", function() {
  // code…
});

This will allow your code to run after the DOM is loading, making your code able to see the HTML and access it.


Post a Comment for "Setting A Variable To A String Returning As Null"