Hi,
I have a download counter on my website, here, that I am trying to get to work correctly.
The files for download are displayed in a 2 column table along with their respective download counts.
Here is the code that displays the table and files on the page:
When the user clicks on a file it initiates the download process and updates the counter via a call to my js script, see below:-
Now my problem is that the click event is on the <TR> tag of the table and even when a user clicks in cell2 of the table the counter will increase, although it does return to normal after a page refresh but obviously the file download will not start.
I would really like to isolate the event so it only actually happens when cell1 where the actual filename is, is clicked.
I have tried changing the event to happen on the <TD> tag, while this still activates the download, the counter will not increase and I still have the same problem in clicking on cell2 increases the counter without downloading.
I hope all this makes some kind of sense and would appreciate any help at all.
Regards
K..,
I have a download counter on my website, here, that I am trying to get to work correctly.
The files for download are displayed in a 2 column table along with their respective download counts.
Here is the code that displays the table and files on the page:
Code:
<center>
<table>
<tr>
<td>File Name</td>
<td>Downloads</td>
</tr>
<?php
foreach($files_array as $key=>$val)
{
echo '
<tr>
<td><a href="http://www.madtogger.co.uk/dlc_download.php?file='.urlencode($val).'">'.substr($val, 0, strpos($val, '.')).'</a></td>
<td><span class="download-count">'.(int)$file_downloads[$val].'</span></td>
</tr>';
}
?>
</table>
</center>
Code:
$(document).ready(function(){
/* This code is executed after the DOM has been completely loaded */
$('tr').click(function(){
var countSpan = $('.download-count',this);
countSpan.text( parseInt(countSpan.text())+1);
});
});
I would really like to isolate the event so it only actually happens when cell1 where the actual filename is, is clicked.
I have tried changing the event to happen on the <TD> tag, while this still activates the download, the counter will not increase and I still have the same problem in clicking on cell2 increases the counter without downloading.
I hope all this makes some kind of sense and would appreciate any help at all.
Regards
K..,
Comment