Here you have it...
Hope this will solve the issue...
<html>
<head>
<title>javascript1</title>
</head>
<script lnaguage="javascript">
function Init()
{
var table = document.createElement("tbody");
var newrow,newcol,tmp;
var array = new Array(16);
for (var i=0 ; i<16 ; i++)
array[i] = 0;
for (var row = 0 ; row <4 ; row++)
{
newrow = document.createElement("tr");
for (var col = 0 ; col<4 ; col++)
{
newcol = document.createElement("td");
var button = document.createElement('input');
button.type = 'button';
button.width = '60';
button.height = '60';
button.id = (row*10 + col).toString();
newcol.appendChild(button);
newrow.appendChild(newcol);
if (row == 3 && col == 3)
break;
while (array[tmp = Math.floor((15)*Math.random()) + 1] == 1);
array[tmp]++;
button.value = tmp;
}
table.appendChild(newrow);
}
gameTable.appendChild(table);
}
document.onclick = function(e) {
e = e ? e : window.event;
t = e.target ? e.target : e.srcElement;
if (document.getElementById && t.type == 'button') {
ids = parseInt(t.id.match(/\d/));
/* You can add more function from the switch method. The only problem you have is that you've set your id's from the maximum count of "col" variable, which is 4 in overall count.
So the first 4 line up of buttons will take this event. The rest will copy the function counting back from 0 to 4, which all the buttons from the 2nd row copy this effect! Things can be fixed by incrementing the col value = to the length of buttons being created by your function.
Im sure it will be easy for you to achieve that. Good day to you... */
switch(ids) {
case 0 : alert('This is function no#' + ids); break;
case 1 : alert('Some function ' + ids + ' To Run'); break;
case 2 : prompt('This is function no#' + ids); break;
case 3 : confirm('This is function no#' + ids); break;
}
}
}
window.onload=Init;
</script>
<body>
<form id="myForm">
<div style=" color:Blue; font-size:large; font-style:oblique; left:500; top:30; position:absolute">
Fifteen Javascript
</div>
<div style="left:450; top:150; position:absolute"">
<table id="gameTable"></table>
</div>
</form>
</body>
</html>