473,394 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Event Listener Fires Twice

Claus Mygind
571 512MB
I am baffled as to why an event listener is firing twice on me.

I have two apps that share the same piece of code. Each app has two search buttons, So a total of 4 search buttons. Each executing the same code with different parameters. Of the 4 buttons only one fails by firing twice on a single click.

Here are the buttons as coded in the two apps:
Expand|Select|Wrap|Line Numbers
  1. from App1:
  2. <input 
  3.     type="button"         
  4.     id  ="sbReqClient"         
  5.     value="Change Client"         
  6.     class="InputText"
  7.     tabindex="-1" 
  8. />
  9. <input 
  10.     type="button"         
  11.     id  ="sbComClient"         
  12.     value="Change Client"         
  13.     class="InputText"
  14.     tabindex="-1" 
  15. />
  16.  
  17. from App2:
  18. <input 
  19.     type="button"         
  20.     id  ="sbReqClient"         
  21.     value="Change Client"         
  22.     class="InputText"
  23.     tabindex="-1" 
  24. />
  25. This button when clicked fires twice
  26. <input 
  27.     type="button"         
  28.     id  ="sbComClient"         
  29.     value="Change Client"         
  30.     class="InputText"
  31.     tabindex="-1" 
  32. />
  33.  

Each button is assigned an event listener like so. I copied this code from the one app to the other app, so the code is identical.
Expand|Select|Wrap|Line Numbers
  1.  
  2. For button 2 in app 2 this eventlistener fires twice.
  3.     g.sbComClient = document.getElementById('sbComClient');
  4.     if (g.sbComClient.addEventListener)
  5.     {
  6.         g.sbComClient.addEventListener("mousedown",
  7.                                         function(evt)
  8.                                         {
  9.                                             smallSearch('Client Id','10','8','CLIENT','ID','ComClient','Yes','startSmallSearch');
  10.                                         },
  11.                                     false)
  12.     }
  13.  
  14.     g.sbReqClient = document.getElementById('sbReqClient');
  15.     if (g.sbReqClient.addEventListener)
  16.     {
  17.         g.sbReqClient.addEventListener("mousedown",
  18.                                         function(evt)
  19.                                         {
  20.                                             smallSearch('Client Id','10','8','CLIENT','ID','ReqClient','Yes','startSmallSearch');
  21.                                         },
  22.                                     false)
  23.     }
  24.  
  25. Here is code from app1 which fires properly so you can see all the code involved
  26.     g.sbComClient = document.getElementById('sbComClient');
  27.     if (g.sbComClient.addEventListener)
  28.     {
  29.         g.sbComClient.addEventListener("mousedown",
  30.                                         function(evt)
  31.                                         {
  32.                                             smallSearch('Client Id','10','8','CLIENT','ID','ComClient','Yes','startSmallSearch');
  33.                                         },
  34.                                     false)
  35.     }
  36.  
  37.     g.sbReqClient = document.getElementById('sbReqClient');
  38.     if (g.sbReqClient.addEventListener)
  39.     {
  40.         g.sbReqClient.addEventListener("mousedown",
  41.                                         function(evt)
  42.                                         {
  43.                                             smallSearch('Client Id','10','8','CLIENT','ID','ReqClient','Yes','startSmallSearch');
  44.                                         },
  45.                                     false)
  46.     }
  47.  
  48.  
  49.  
From this point forward all 4 buttons run the exact same code from linked files.

Where should I be looking for the cause of the problem?
What are some possible explanations for multiple firings? I understand double click and that is not the problem, I have checked that.
Dec 2 '11 #1

✓ answered by Claus Mygind

I found the error. The one button firing twice had the event listener defined twice. Too much copying of the code. Well there goes 2 hours of my life that could have been spent better.

1 7367
Claus Mygind
571 512MB
I found the error. The one button firing twice had the event listener defined twice. Too much copying of the code. Well there goes 2 hours of my life that could have been spent better.
Dec 2 '11 #2

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

Similar topics

2
by: Jonas Nilsson | last post by:
Hi! I have a DataList with some linkbuttons, and when i click them the eventhandler fires twice. Is there a way around this?, it's the same problem with the repeater and datagrid control...
7
by: Jay Douglas | last post by:
Hello all, I have a asp.net page that creates a pdf on the fly and sends the pdf down to the browser. When calling the page up in IE the Page_Load event is fried twice. This doesn't happen with...
5
by: Asa Monsey | last post by:
I am having a problem that the page load event fires twice in reponse to an autopostback. The first time, the IsPostBack property is true, and the second time it it false. This is causing many...
0
by: Jim Heavey | last post by:
Why does the method for on_ItemCommand fire twice when I press a button contained within my grid? My dgTask_ItemCommand which is the procedure name assigned to the "on_ItemCommand" fires twice...
1
by: Bill Manring | last post by:
The startup page for my ASP.NET application is an HTML frames page with two frames. This seems to cause the Session_Start event in the Global.asax file to fire twice. When I change the startup...
0
by: JeffM | last post by:
This seems odd, but it appears that the Page_Unload event is fired twice on a Response.Redirect or a Server.Transfer. The output below demonstrates that during the move from the first to the 2nd...
3
by: doctorle | last post by:
I'm surprised that the Current event of forms always fires twice (Access XP). I have quite a lot of processing done in the current event, how to make the code run just once? Thanks
5
by: docw | last post by:
SelectionChangeCommitted event fires twice Hi, Please have a look at the following ComboBox behavior. With the code below, if you click in the dropdown list with the mouse to select an item ,...
2
by: Simon Harvey | last post by:
Hi Guys, Can anyone tell me why the DataGridView.SelectionChanged event fires twice when I databind to it. If I do the following, the first row is selected automatically, but the changed...
0
by: manywolf | last post by:
I have an aspx page that fires the page load event twice for every load. I tried every fix that was suggested in all the posts on this and other forums. None changed the behavior. After one post that...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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...

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.