Hej igen
Så lykkedes det at kunne højre klikke i en tabelcelle ud fra denne kode:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Lotto.aspx.cs" Inherits="LottoProgram.LottoClass" %>
<!DOCTYPE html>
<html xmlns="
http://www.w3.org/1999/xhtml"><head>
<title>Find table cell value on cell (table) click using JavaScript</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>Table Example, constructed programmatically</h3>
<asp:Label ID="Label1" runat="server" Text="LOTTO">LOTTO</asp:Label>
<asp:Table ID="Table1"
GridLines="Both"
HorizontalAlign="Center"
Font-Names="Verdana"
Font-Size="16pt"
CellPadding="15"
CellSpacing="10"
runat="server"
Style="cursor: pointer;"
BorderWidth="3px" />
<br />
</div>
</form>
<script type="text/javascript">
var tbl = document.getElementById("Table1");
var button;
var x = document.getElementById("Table1").cells;
window.oncontextmenu = function () {
return false; // cancel default menu
}
if (tbl != null) {
for (var i = 0; i < tbl.rows.length; i++) {
for (var j = 0; j < tbl.rows[i].cells.length; j++)
tbl.rows[i].cells[j].onclick = function () { getval(this); };
}
}
if (tbl != null) {
for (var i = 0; i < tbl.rows.length; i++) {
for (var j = 0; j < tbl.rows[i].cells.length; j++)
tbl.rows[i].cells[j].oncontextmenu = function () { getval(this); };
}
}
function getval(cel) {
var x = document.getElementById("Table1").cells;
var nr = cel.innerHTML;
WhichButton(event);
if (button == 1) {
x[nr - 1].bgColor = "green";
}
else if (button == 3) {
x[nr - 1].bgColor = "red";
}
}
function WhichButton(event) {
// all browsers except IE before version 9
if ('which' in event) {
switch (event.which) {
case 1:
//alert("Left button is pressed");
return button = 1;
break;
case 2:
return button = 2;
//alert("Middle button is pressed");
break;
case 3:
//alert("Right button is pressed");
return button = 3;
break;
}
}
else {
// Internet Explorer before version 9
if ('button' in event) {
var buttons = "";
if (event.button & 1) {
buttons += "left";
}
if (event.button & 2) {
if (buttons == "") {
buttons += "right";
}
else {
buttons += " + right";
}
}
if (event.button & 4) {
if (buttons == "") {
buttons += "middle";
}
else {
buttons += " + middle";
}
}
alert("The following buttons are pressed: " + buttons);
}
}
}
</script>
</body>
</html>
jeg bruger det samme loop til at finde den enkelte celle når jeg klikker i tabeller.
ved onclick = venstre klik.
ved oncontextmenu = højre klik samtidig med at jeg har slået window.oncontextmenu fra.
mange tak for hjælpen.