By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,237 Members | 1,162 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,237 IT Pros & Developers. It's quick & easy.

Button executes every other click

100+
P: 115
Hi,

I have an HTML button that i want to execute javascript on every mouse down that occurs. I'v tried using the onmousedown and the onclick events but the button only executes on every second click. This button is meant to increment once on every click, I dont want the user double clicking for every increment.

Is there a way to make a button execute on every click?

[HTML]<input id="btnMoveUp" style="left: 465px; position: absolute; top: 110px; width: 45px; height: 24px;" type="button" value="Up" onmousedown="return btn_move_up()" />[/HTML]
Jun 3 '08 #1
Share this Question
Share on Google+
8 Replies


100+
P: 115
Hmm well I solved my issue by using the onclick and ondblclick events pointing to the same funciton. This works in my situation, but is there a cleaner way to do this?
Jun 3 '08 #2

eWish
Expert 100+
P: 971
Moving thread to Javascript / DHTML / Ajax Forum.

--Kevin
Jun 3 '08 #3

acoder
Expert Mod 15k+
P: 16,027
onclick should execute a function on every click. Can you show the code for btn_move_up().
Jun 4 '08 #4

100+
P: 115
onclick should execute a function on every click. Can you show the code for btn_move_up().
Thats what i would have thought too..

Expand|Select|Wrap|Line Numbers
  1. function btn_move_up()
  2. {
  3.     var lst = document.getElementById("lstViewColumns");
  4.  
  5.     if(lst.selectedIndex != -1 && lst.selectedIndex != 0)    
  6.         lst.insertBefore(lst.options[lst.selectedIndex], lst.options[lst.selectedIndex - 1]);    
  7. }
Jun 9 '08 #5

acoder
Expert Mod 15k+
P: 16,027
A quick test works fine:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4.       function btn_move_up()
  5.       {
  6.           var lst = document.getElementById("lstViewColumns");
  7.           if(lst.selectedIndex != -1 && lst.selectedIndex != 0)   
  8.               lst.insertBefore(lst.options[lst.selectedIndex], lst.options[lst.selectedIndex - 1]);   
  9.       }
  10. </script>
  11. </head>
  12. <body>
  13. <form>
  14. <input id="btnMoveUp" style="left: 465px; position: absolute; top: 110px; width: 45px; height: 24px;" type="button" value="Up" onclick="btn_move_up()" />
  15. <select id="lstViewColumns">
  16. <option>test
  17. <option>test1
  18. <option>test2
  19. <option>test3
  20. </select>
  21. </form>
  22.  
  23. </body>
  24. </html>
Maybe you have something else that's causing the problem.
Jun 9 '08 #6

Plater
Expert 5K+
P: 7,872
One might guess that it's also an ASP.NET button performing a postback?
Jun 9 '08 #7

100+
P: 115
Try it like this:

[HTML]<html>
<head>
<script type="text/javascript">
function btn_move_up()
{
var lst = document.getElementById("lstViewColumns");
if(lst.selectedIndex != -1 && lst.selectedIndex != 0)
lst.insertBefore(lst.options[lst.selectedIndex], lst.options[lst.selectedIndex - 1]);
}
</script>
</head>
<body>
<form>
<input id="btnMoveUp" style="left: 465px; position: absolute; top: 110px; width: 45px; height: 24px;" type="button" value="Up" onclick="btn_move_up()" />
<select id="lstViewColumns" size=10>
<option>test
<option>test1
<option>test2
<option>test3
<option>test4
<option>test5
<option>test6
</select>
</form>

</body>
</html>[/HTML]

edit: I noticed its not so much skipping a click..as it is a time delay as to when you can click again. imagine 15 items in that list having to wait that extra second every click. if you add the ondblclick pointing to the same function it gives me the desired action.
Jun 10 '08 #8

acoder
Expert Mod 15k+
P: 16,027
Which browser are you testing on and how fast is the machine? Is there a load? Also how fast are you clicking?
Jun 10 '08 #9

Post your reply

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