faqts : Computers : Programming : Languages : JavaScript : Links

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

24 of 83 people (29%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

Using return !count++ in a onClick event enables to disable a link, but how to know if it's clicked for the 1st,2nd,3rd times ?....

Jun 12th, 2002 07:42
David Blackledge, stéphane royer,


onclick="if(!count++) return true;else { alert(count+' clicks'); return 
false; }"
So, the variable count will tell you how many times it's been clicked, 
after the ++ line has been run.
(The if statement takes advantage of the postfix operator's feature of 
returning the value of the variable BEFORE it's incremented.  Remaining 
code sees count with it's value AFTER it's incremented.)
David
http://David.Blackledge.com