473,549 Members | 2,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Onclick handler firing multiple times when it shouldn't?

I have a web page that tracks clicks on certain hyperlinks. I am using
attachEvent() to attach to the document onClick handler, for IE browsers.
It works fine, except that for about 1 out of every 6 clicks, I get 2 to 4
click events for a single click. I know this because each time the
hyperlink is clicked, I write a record to a MySQL database. I write the
record to the database by setting the SRC property of an IFRAME on the page,
to a tracking script.

If I look at the database, for 1 out of every 6 clicks, I see 2 to 4 records
for the same click event (occassionally as many as 6 records). They are at
least 1 second and at most 7 seconds apart from each other.

What could be causing this and how can I fix it?

Thanks.
Jul 23 '05 #1
4 4615
On Sat, 30 Oct 2004 13:29:01 -0400, Robert Oschler
<no************ @nospam.com> wrote:

[snip]
If I look at the database, for 1 out of every 6 clicks, I see 2 to 4
records for the same click event (occassionally as many as 6 records).
They are at least 1 second and at most 7 seconds apart from each other.
With that much separation, the most logical explanation is that someone's
clicking more than once (though I'm sure you've already ruled that out).
What could be causing this and how can I fix it?


Without seeing a demonstration, it's very difficult to say.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
Robert Oschler wrote on 30 okt 2004 in comp.lang.javas cript:
What could be causing this and how can I fix it?


A click-only-once should be simple:
var myClick = false;

function clicked(){
if (myClick) return false;
myClick = true;
do something()
return true;
}

............... .............

onclick = "clicked()"

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 23 '05 #3

"Evertjan." <ex************ **@interxnl.net > wrote in message
news:Xn******** ************@19 4.109.133.29...
var myClick = false;

function clicked(){
if (myClick) return false;
myClick = true;
do something()
return true;
}

............... ............

onclick = "clicked()"

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)


Evertjan,

The problem with that approach is that more than one hyperlink is being
tracked. If I read it right, once any hyperlink was clicked, that function
would return false from then on.

Thanks.
Jul 23 '05 #4
Robert Oschler wrote on 30 okt 2004 in comp.lang.javas cript:
Evertjan,

The problem with that approach is that more than one hyperlink is
being tracked. If I read it right, once any hyperlink was clicked,
that function would return false from then on.


Only the one single hyperlink were you put the string

onclick = "return clicked()"

in. [Do mind the return here!]

=============== =============== ===

If you want to use it in different hyperlinks you could have different
myClick variables but I would suggest a timeout instead:

=============== =============== ====

var myClick = false;

function clicked(){
if (myClick) return false;
myClick = true;
setTimeout('myC lick = false;',200)
return true;
}
<a onclick="return clicked(xx)" src='xx.html'>x x</a>
<a onclick="return clicked(yy)" src='yy.html'>y y</a>
<a onclick="return clicked(zz)" src='zz.html'>z z</a>

NOT TESTED !!!

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

32
14776
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
2
1849
by: schiefaw | last post by:
Hello, I created a custom event "Public Event ApprovalChangedEvent()" and set a function to catch it "Private Sub laset_ApprovalChangedEvent() Handles laset.ApprovalChangedEvent". The problem is that the handler is invoked five times. I have set breakpoints so I can see the the event is only raised once. The handler itself just sets some...
17
10168
by: dan_williams | last post by:
I have the following test web page:- <html> <head><title>Test</title> <script language="Javascript"> <!-- function fnTR() { alert("TR"); }
2
2820
by: =?Utf-8?B?Uml0YUc=?= | last post by:
I posted this question in the C# discussion group but am posting it here also since ASP is involved. I'm new to C# and need some help regarding an onClick event not firing. I have a data grid that I add a cell to programatically. The cell is a hyperlink and the onClick is set to _doPostBack. In my code I handle the event but when I click...
2
3902
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite well, so at times it is tempting just to port parts of it over mostly as-is. In fact, one MSDN article I read suggested using straight HTML wherever...
8
4948
by: Dan Rumney | last post by:
All, I have a web page (copied below) with 3 images on it of fixed dimensions. Each image has a map associated with it In the maps, there are a number of areas with an onClick handler registered (in this sample, just an alert) The HTML is valid.
21
13423
by: brucedodds | last post by:
I have an Access 2003 form bound to a SQL Server table via ODBC. Often clicking a button on the form has the effect of requerying the form rather than firing the OnClick event. Does anyone have an explanation? Is this evidence of corruption, or a known side effect? TIA Bruce
9
10019
by: skultetc | last post by:
Hey all, I have a div displayed as a block with an onclick event that shows/ hides a different div underneath it. There is a link within the first div that takes the user to a different page. My problem is that if the user clicks the link, the onclick is also executed and the div underneath is shown/hidden before the browser changes pages,...
0
7462
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7492
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7823
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5381
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5101
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3510
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3491
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1069
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
777
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.