javascript canvas is null
<p>just starting in JavaScript and I'm getting the error "canvas is null"</p>

<pre><code>function draw() {  

    var canvas = document.getElementById("canvas");  
    var ctx = canvas.getContext("2d"); 
    var width,height;

    width = canvas.width;
    height = canvas.height;

    ctx.fillStyle = "rgb(0,0,0)";  
    ctx.fillRect (10, 10, width, height); 
    ctx.fillStyle = "rgb(200,0,0)";  
    ctx.fillRect (posx, posy, 30, 30); 

}
var posx;
var posy;
function getMouse(e){
    posx=0;posy=0;
    var ev=(!e)?window.event:e;//Moz:IE
    if (ev.pageX){
        posx=ev.pageX;posy=ev.pageY//Mozilla or compatible
    }
    else if(ev.clientX){
        posx=ev.clientX;posy=ev.clientY//IE or compatible
    }
    else{
        return false//old browsers
    }
        document.getElementById('mydiv').firstChild.data='X='+posx+' Y='+posy;
}
setInterval(draw(),1000);
</code></pre>

<p>The code basically draws a box at the mouse position ( at least that's what it was suppose to do...)</p>

<p>Btw "canvas" is the id of the canvas.
THANKS!</p>
