6. More About Events and Actions
Trigger-Delayed Events
<< Conditional Events
|
Back to Main
|
Javascript Actions, Alerts and Confirmations >>
View Source
will open in a new window
Triggering Events after a Delay
Sometimes, you may want events to trigger their assigned actions after a delay. A good example of this here is the
QKeyPressEvent
we added below. As the user enters in data into the textbox, we make an AJAX call to update the label. However, in order to make the system a bit more usable and streamlined, we have added a half-second (500 ms) delay on the
QKeyPressEvent
, so that we are not making too many AJAX calls as the user is still entering in data.
Basically, this allows the action to be triggered only after the user is done typing in the data.
Note that we maybe could have used a QChangeEvent on the textbox to achieve a similar effect. But realize that QChangeEvent (which utilizes a javascript
onchange
event handler) will only be triggered after the control
loses focus
and has been changed -- it won't be triggered purely by the fact that the text in the textbox has been changed.
Random Data
What You Entered
<none>