473,473 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

JS Click event issue.

2 New Member
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:

Expand|Select|Wrap|Line Numbers
  1. <center>
  2. <table>
  3. <tr>
  4. <td>File Name</td>
  5. <td>Downloads</td>
  6. </tr>
  7.  <?php 
  8.  
  9.         foreach($files_array as $key=>$val)
  10.         {
  11.             echo '
  12. <tr>
  13. <td><a href="http://www.madtogger.co.uk/dlc_download.php?file='.urlencode($val).'">'.substr($val, 0, strpos($val, '.')).'</a></td>
  14. <td><span class="download-count">'.(int)$file_downloads[$val].'</span></td>
  15. </tr>';
  16.         }
  17.  
  18.     ?>
  19.  
  20. </table>
  21. </center>
  22.  
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:-

Expand|Select|Wrap|Line Numbers
  1. $(document).ready(function(){
  2.     /* This code is executed after the DOM has been completely loaded */
  3.  
  4.     $('tr').click(function(){
  5.  
  6.         var countSpan = $('.download-count',this);
  7.         countSpan.text( parseInt(countSpan.text())+1);
  8.     });
  9. });
  10.  
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..,
Mar 26 '10 #1
3 1839
Dormilich
8,658 Recognized Expert Moderator Expert
as far as I can tell, the download is not triggered by JavaScript …

if you put the increment event in the TD, you have to fetch the span from the next sibling. jQuery certainly has an accessor for that.
Mar 26 '10 #2
MadTogger
2 New Member
Thanks for the reply.

I am pretty new at all this but I do understand that the download is not triggered by the js file, that seems to be only used for updating the counter.

How would you code it to resolve the issue I am having?

An example would probably suffice for me to then work through it.

Regards..,

K
Mar 26 '10 #3
Dormilich
8,658 Recognized Expert Moderator Expert
I don’t know because I don’t use jQuery. you have to search in the documentation or ask someone good at jQuery.
Mar 26 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: news.btinternnet.com | last post by:
I can do this in IE myLink.click(); //Invoking the handler as if the user had clicked on the link themselves. I need to be able to do the same in Netscape Navigator, can anyone help ?
7
by: Marina | last post by:
Imagine a form with some fields and an OK buttons that saves the information. Each field has validation logic in the Validating event. If the input is not valid, the control's value is replaced...
11
by: CW | last post by:
I have message entry screen that's causing me a bit of an issue. At the moment, there are 2 buttons, one is used to send message to another user (btnSend) and another is used to send messages to...
3
by: Imran Aziz | last post by:
Hello All, I have a search text and button that post data and my button handler filters the repeater control. However when the button is clicked the first time. The page_load event is being called...
0
by: Demetri | last post by:
I have created a web control that can be rendered as either a linkbutton or a button. It is a ConfirmButton control that allows a developer to force a user to confirm if they intended to click it...
3
by: graphicsxp | last post by:
Hi, I've written some javascript function so that if a textbox has the focus and the user press enter, it triggers a click on a button 'associated' to this textbox (see code at the end) The...
12
by: cj | last post by:
I would like to have menu items a main menu bar that represent the days of the week. When you click on them they alternate from checked to unchecked. Right now I have 7 subs that look like this...
4
by: Bob | last post by:
Hi, I'm working with VWD and i defined programmatically a button (in code-behind) with an ID. So I expect to see beside "Page Events" and "Form1" my button "b1" in order to use the Click event....
4
by: mohaaron | last post by:
This seems like it should be simple to do but for some reason I have been unable to make it work. I would like to databind a SqlDataSource to a GridView during the click event of a button. This...
1
by: \Ji Zhou [MSFT]\ | last post by:
Hello Jason, Thanks for using Microsoft Newsgroup Support Service, my name is Ji Zhou and I will be working on this issue with you. I have tried to but cannot reproduce your issue on my side....
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.