Saturday, May 25, 2024
 Popular · Latest · Hot · Upcoming
39
rated 0 times [  42] [ 3]  / answers: 1 / hits: 104285  / 11 Years ago, thu, january 9, 2014, 12:00:00

I'm learning JavaScript and recently I have been experimenting with Mouse events, trying to understand how they work.



<html>
<head>
<title>Mouse Events Example</title>
<script type=text/javascript>
function handleEvent(oEvent) {
var oTextbox = document.getElementById(txt1);
oTextbox.value += n + oEvent.type;

if(oEvent.type==click)
{
var iScreenX = oEvent.screenX;
var iScreenY = oEvent.screenY;
var b = Clicked at +iScreenX+ , +iScreenY;

alert(b);
}
}
function handleEvent1(oEvent) {
// alert(Left Window);
}
</script>
</head>
<body>
<p>Use your mouse to click and double click the red square</p>
<div style=width: 100px; height: 100px; background-color: red
onmouseover=handleEvent(event)
onmouseout=handleEvent1(event)
onmousedown=handleEvent(event)
onmouseup=handleEvent(event)
onclick=handleEvent(event)
ondblclick=handleEvent(event) id=div1></div>
<p><textarea id=txt1 rows=15 cols=50></textarea></p>
</body>




this is the code I have been trying to understand. Can anyone help me to Create a HTML table that upon clicking in a cell of the table user is told cell he is clicking in?
been stuck on it for time, thanks for help.


More From » html

 Answers
3
var table = document.getElementById(tableID);
if (table != null) {
for (var i = 0; i < table.rows.length; i++) {
for (var j = 0; j < table.rows[i].cells.length; j++)
table.rows[i].cells[j].onclick = function () {
tableText(this);
};
}
}

function tableText(tableCell) {
alert(tableCell.innerHTML);
}


is an example of what you could do. DEMO


[#73274] Wednesday, January 8, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kalistaz

Total Points: 0
Total Questions: 100
Total Answers: 106

Location: Bermuda
Member since Thu, Apr 20, 2023
1 Year ago
;