My code registers an on click event, which opens a dialogue box and presents some information. I want the dialogue box to also display where on the page the user clicks. Currently that information is presented in an alert box, but I want it to be in the dialogue box.
Could anyone possibly help me with this problem?
HTML
<canvas id="myCanvas" height ='1000' width='1000' onclick = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block';" width="300" height="150" style="border:1px solid #d3d3d3;" ></canvas>
<div id="light" class="white_content"><a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'">Close</a><p>Stress</p><p>Measurement</p><p>Height</p><p>Width</p><p>Diameter</p></div>
<div id="fade" class="black_overlay" onclick="document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'"></div>
CSS
.black_overlay{
display: none;
position: fixed;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
background-color: black;
z-index:1001;
opacity:.80;
filter: alpha(opacity=80);
}
.white_content {
display: none;
position: fixed;
top: 10%;
left: 25%;
width: 50%;
height: 216px;
padding: 15px;
border: 15px solid #808080;
background-color: white;
z-index:1002;
overflow: auto;
}
Javascript
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var gCanvasElement = ctx;
ctx.strokeStyle="#FF0000";
ctx.strokeRect(20,20,800,600);
// Positions are hardcoded to make sure that circle starts from the right place
var startX = 55;
var startY = 55;
console.clear();
for(var i=1;i<=8;i++){
console.group(i);
for(var j=1;j<=i;j++){
ctx.beginPath();
ctx.strokeStyle='green';
//radius is hardcoded to 30 for testing purpose
ctx.arc(startX*j + (j-1)*10,startY*i + (i-1)*10,30,0,2*Math.PI);
ctx.stroke();
//console log
console.group(j);
console.log(startX*j + (j-1)*10);
console.log(startY*i + (i-1)*10);
console.groupEnd(j);
}
console.groupEnd(i);
}
var canvasBg = document.getElementById('myCanvas');
var ctxBg = canvasBg.getContext('2d');
var mouseX;
var mouseY;
canvasBg.addEventListener('mousemove', mouseMoved, false);
canvasBg.addEventListener('click', mouseClicked, false);
function mouseMoved(e){
mouseX = e.pageX-canvasBg.offsetLeft;
mouseY = e.pageY-canvasBg.offsetTop;
}
var posX = Math.ceil((mouseX-25)/65);
var posY = Math.ceil((mouseY-25)/65);
function mouseClicked(e){
alert('X: ' + Math.ceil((mouseX-25)/65) + ' Y: ' + Math.ceil(((j-1)*65-mouseY+25)/65));
}
window.onload=func
function func()
{
document.getElementById("d").innerHTML="String"
}