How can I print the index of table rows and data on click in javascript?
<html>
<head>
<title>Table Creation</title>
<script language="javascript" type="text/javascript">
function createTable()
{
document.write("<table >");
for (var x = 1; x < 10; x++) {
document.write("<tr >");
for(var y = 1; y < 10; y++) {
document.write("<td><button onclick='alert(\\"" + x + "," + y + "\\")'>index</button></td>");
}
document.write("</tr>");
}
document.write("</table>");
}
</script>
</head>
<body>
<button onclick="createTable()">Try it</button>
<div >
</div>
</body>
</html>
For example, clicking on a cell in row 1 would display an alert with the indexes ((1,1),(1,2),(1,3)...), while clicking on row 2 would show ((2,1),(2,2),(2,3))