-2

I need to make a button which, when pressed, will trigger a jQuery.post() event repetitively. The second event should be triggered 500ms after the first, and a volley of rapid-fire events should be subsequently triggered thereafter.

In other words, the button should simulate what happens when you press the Volume up/down buttons of a remote control. I suspect that there may be a jQuery method that does just that - but I wouldn't know how. Do you?

here is the code:

jQuery("projTable").click(function(event) {
var contentPanelId = jQuery(this).attr("id");
}); 
$("[class*=triggerZone]").children().click(function(event) 
    {var buttonArray = [event.target.id, event.target.className, event.target.parentNode.parentNode.parentNode.id];
    var triggerObject = 
        {eventTargetId: event.target.id, 
         eventTargetClassName: event.target.className.split(" "),
         eventTargetParentNodeParentNodeId: event.target.parentNode.parentNode.id,
         eventTargetParentNodeParentNodeParentNodeId: event.target.parentNode.parentNode.parentNode.id};
    processAction(triggerObject);});
 });

 function processAction(triggerObject) 
{ $.ajax({
type: "POST",
url: '../json_api/WohnZimmerControl.php',
data: triggerObject,
} 
});
Cœur
  • 37,241
  • 25
  • 195
  • 267
aag
  • 680
  • 2
  • 12
  • 33
  • OK, ok, I see that I am collecting downvotes at an impressive speed. Would anybody at least care to explain what is so offensive about my question? – aag May 01 '16 at 18:58
  • 1
    @aag Refer to adeneo's comment. You can't expect us to write code for you. Show us what you've tried. There are many things that you can piece together to achieve what you want: you just need to collect your thoughts and do some homework yourself. SO is *not* a code-writing service. – Terry May 01 '16 at 19:00
  • well, I did write a button with an attached CSS class. I use the class name to inform a jQuery post event to a PHP server, which then moves the volume up-and-down. All of this works well, but not repetitively. I'll paste the code down here: – aag May 01 '16 at 19:07
  • Don't paste your code in the comments. Modify/edit your question instead. – Terry May 01 '16 at 19:08
  • Honestly I wasn't expecting anybody to write code for me - that's why I didn't enter any code. I was just hoping that some good soul might point me in the right direction. There are so many cool ways to get things done out there, and some people (but obviously not everybody) enjoy giving some directions to their fellow humans. – aag May 01 '16 at 19:16
  • 1
    The problem with these "point me to right direction" questions is that it's really frustrating trying to guess what exactly is the "right direction" you're looking for. For example, someone could have pointed you to how to make a button with HTML and CSS, but you already have that so that would lead to a back-and-forth conversation about what exactly it is that you need, and Stack Overflow isn't really meant for that kind of discourse. – JJJ May 01 '16 at 19:18
  • I accept the critique, I admit that the question was poorly formulated, and I apologize for any frustration or anger that was caused. The question is: **"is there any way to cause an event to be triggered repetitively when a HTML/CSS button is kept pressed?"**. I would be grateful for an indication on how it could be formulated more precisely. – aag May 01 '16 at 19:23

1 Answers1

2

As said in this answer, you can handle mousedown event.

When user click on button, that will call mousedown event and when user leave the button it will fire mouseleave or mouseup event.

What you can do is to start a timer after mouseup, and post data on every timer iteration. you stop timer on mouseup or mouseleave.

Community
  • 1
  • 1
Ygalbel
  • 5,214
  • 1
  • 24
  • 32
  • Thank you @Ygalbel. I really appreciate. That helps a lot - and it's exactly the kind of advice that I was hoping to read. It's nice to see that the SO community does not exclusively consist of condescending guardians-of-orthodoxy and hobby policemen! – aag May 01 '16 at 19:47