So I have coded a small javascript to pass on few variables to another function however when I am running it nothing is happening any idea where am I going wrong?
<canvas id="canvas" width="1350" height="400"
style="background-color:#333" onmousemove="F(event)">
</canvas>
<script type="text/javascript">
function Reset()
{
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
ctx.font = "30px Arial";
ctx.fillStyle = "#333";
ctx.fillRect(0,0,1350,400);
}
function F(e,x1,y1,x2,y2)
{
var mouseX, mouseY;
var xyz,xx,yy,xxx,yyy;
xx = x1;
yy = y1;
xxx = x2;
yyy = y2;
if(e.offsetX) {
mouseX = e.offsetX;
mouseY = e.offsetY;
}
else if(e.layerX) {
mouseX = e.layerX;
mouseY = e.layerY;
}
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
ctx.font = "30px Arial";
ctx.fillStyle = "#FF0000";
ctx.fillRect(xx,yy,xxx,yyy);
Handler(mouseX,mouseY);
}
function Handler(val,val1)
{
mouseX1 = val;
var mouseX2,mouseY2,mouseY1,mouseX1;
mouseX2 = mouseX1 + 20;
mouseY2 = mouseY2 + 20;
mouseY1 = val1;
document.getElementById("x").innerHTML= mouseX1;
document.getElementById("y").innerHTML= mouseY1;
F(e,mouseX1,mouseY1,mouseX2,mouseY2);
}
</script><center>
<p id="x"></p><p id="y"></p>
In the above code I am trying to pass out few values to the function F() to draw a rectangle according to the values forwarded. However I see nothing any idea where am I going wrong?
Thanks