See my other post in this thread. It uses just one function. However, less is not always the best. Here is valid code for the same thing with structure (HTML markup), presentation (CSS style) and effects (javascript) kept separate as is generally recommended:
Code:
<!DOCTYPE html>
<html>
<head>
<title>Cell X Row Indexes - Demo#2</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
#tablo1 {
border: 2px solid;
border-color: #afafaf #000 #000 #afafaf;
empty-cells: show;
}
#tablo1 td {
border: 1px solid;
border-color: #000 #afafaf #afafaf #000;
}
#idx {
text-align: right;
padding-right: 0.5em
}
#ci {
font-weight: bold;
text-align: center;
}
</style>
<script type="text/javascript">
(function(){
var table, rowlimit;
function ci(e){
table = table || document.getElementById('tablo1');
rowlimit = rowlimit || table.rows.length - 1;
e = e || event;
var t = e.target || e.srcElement, c, r;
if(typeof (c = t.cellIndex) === 'number'){
r = t.parentNode.rowIndex;
r && r < rowlimit && (function(){document.getElementById('ci').innerHTML = c + ' x ' + r;})();
}
}
if (document.addEventListener){
document.addEventListener('click', ci, false);
}
else if (document.attachEvent){
document.attachEvent('onclick', ci);
}
})();
</script>
</head>
<body>
<table border="1" id="tablo1">
<tr>
<th>P.tesi</th>
<th>Sali</th>
<th>Çarsamba</th>
<th>Persembe</th>
<th>Cuma</th>
<th>C.tesi</th>
<th>Pazar</th>
</tr>
<tr>
<td>26</td>
<td>27</td>
<td>28</td>
<td>29</td>
<td>30</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>2</td>
<td>3</td>
<td>13</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
</tr>
<tr>
<td>16</td>
<td>17</td>
<td>20</td>
<td></td>
<td></td>
<td>21</td>
<td>22</td>
</tr>
<tr>
<td>23</td>
<td>24</td>
<td>25</td>
<td>26</td>
<td>27</td>
<td>28</td>
<td>29</td>
</tr>
<tr>
<td colspan="5" id="idx">indexes:</td>
<td colspan="2" id="ci"></td>
</tr>
</table>
</body>
</html>
Bookmarks