I get Nan when I try to pass a number to .innerHTML

I’m struggling to get the numeric content of a variable to hypeDocument.getElementById(id).innerHTML…
If I pass a letter it works, but a number results in a NaN…I know it must be something simple I’m doing wrong but my limited javascript knowledge is holding me back.

Can someone please help me on my way?
I’m just trying to increment a number on the display of a UI demo…


This should be simple to fix but can you post the code you are using and or a example project…

Here is the code that I’m calling from a scene-keypress-action (‘level’ is the ID of the 2 digit number I want to increase). Ultimately I’d like to use the arrow keys to both increase and decrease as well as have it rund faster the longer i depress the key…but first I just want to work.


var l = hypeDocument.getElementById('level').innerHTML;

l = Number(l) + 1;

hypeDocument.getElementById('level').innerHTML = l;

Sorry, Can you post an example project so I can see what you are actually using.

The code is pretty basic and not showing what we need to see…

You want to make sure l is a number, so use:

var l = parseInt(hypeDocument.getElementById('level').innerHTML);

Number() will pretty much do the same thing AFAIK.

I suspect that @and has formatting in the innerHTML but wanted to see first so as not to keep guessing.

I quick fix for that is to use innerText instead of innerHTML.

Couldn’t get it to work and changed it to a switch with different actions on the arrow keys and suddenly it worked… Wierdly

var x = hypeDocument.getElementById('level').innerHTML;

case 38:

case 40:
x = x-1;

case 39:
hypeDocument.continueTimelineNamed('Main Timeline', hypeDocument.kDirectionForward, false);

case 37:
hypeDocument.goToTimeInTimelineNamed(1, 'Main Timeline');
hypeDocument.continueTimelineNamed('Main Timeline', hypeDocument.kDirectionForward, false);

hypeDocument.getElementById('level').innerHTML = x;