When I, from within the draw loop, get the HTML value it's defines, but if I load it before it enters the loop it seems to forget it.
This is the code I've narrowed it down to:
<html>
<head>
<script type="application/javascript">
setInterval(draw,120);
var value = document.getElementById("uniqueID").value
function draw() {
var canvas = document.getElementById('canvas');
if (canvas.getContext) {
var ctx = canvas.getContext("2d");
ctx.strokeText(value, 200, 200);
}
}
</script>
</head>
<body onload="draw();">
<canvas id="canvas" width="500" height="500"></canvas>
<input type="text" name="name" id="uniqueID" value="5" /><br>
</body>
</html>
Like this the code doesn't work. The text says that value is undefined. But if i move the "var value = do..." to after the draw function it gets it.
I need to define the value outside of the draw function. How can I do that?
Thanks