Skip to content
Advertisement

Fire event on radio group after some time delay

I am searching for a solution to let an event fire on a radio group after some time delay.

Specifically, I need to ask users a question and want to submit their input without having the users click a separate button. At the same time, it shall be possible that the user clicks different radio buttons while considering the answer.

onInput and onChange are both fired immediately after a user click. However, is there another solution?

Here is small example:

JavaScript

I would love to have oninput only fire after, say, 5 seconds without activity in this radio group.

Advertisement

Answer

The OP needs to choose an approach which combines event-delegation and thedebounced handling of a callback-function.

The requirements are that a (or each in case of more than just one) radio-group needs to be entirely nested within a parent-structure where the event-delegation takes place. And each delegation-node of cause needs to have its own debounced event-handler registered to its related input-event.

Additionally a refactoring of the OP’s markup is strongly recommended.

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement