I have a download counter on my site that I am fiddling around with, see here:-
http://www.madtogger.co.uk/page/software
The counter is printed to the screen using the code below:-
Code: Select all
<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: Select all
$(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);
});
});
At the moment whenever a user clicks on the filename, as well as the download starting, the counter is increase by 1, however because the click event is via the <TR> tag the counter also increases if a user just clicks cell2 of the row but this will not start the download.
I am trying to make it possible so the user can only click on the filename to initiate download and the counter update and that no action is taken if they click elsewhere.
I would be eternally grateful for any help here, like I have said, scripting fully using PHP would be a better option for me.
Kind regards..,
K