Event handling is a coding style about handling messages between a source and one or more subscribers. A point listener in the source provide a way which subscribed code can consume messages raised from the source.
Questions tagged [event-handling]
11412 questions
3082
votes
14 answers
event.preventDefault() vs. return false
When I want to prevent other event handlers from executing after a certain event is fired, I can use one of two techniques. I'll use jQuery in the examples, but this applies to plain-JS as well:
1. event.preventDefault()
$('a').click(function (e) {
…
![](../../users/profiles/137467.webp)
RaYell
- 66,181
- 20
- 123
- 149
787
votes
9 answers
window.onload vs document.onload
Which is more widely supported: window.onload or document.onload?
![](../../users/profiles/1551.webp)
Chris Ballance
- 32,056
- 25
- 101
- 147
682
votes
11 answers
jQuery checkbox checked state changed event
I want an event to fire client side when a checkbox is checked / unchecked:
$('.checkbox').click(function() {
if ($(this).is(':checked')) {
// Do stuff
}
});
Basically I want it to happen for every checkbox on the page. Is this method of…
![](../../users/profiles/822229.webp)
AnonyMouse
- 16,228
- 23
- 74
- 128
626
votes
20 answers
jQuery checkbox change and click event
$(document).ready(function() {
//set initial state.
$('#textbox1').val($(this).is(':checked'));
$('#checkbox1').change(function() {
$('#textbox1').val($(this).is(':checked'));
});
$('#checkbox1').click(function() {
if…
![](../../users/profiles/841833.webp)
Professor Chaos
- 7,900
- 7
- 33
- 52
616
votes
15 answers
How to debug JavaScript / jQuery event bindings with Firebug or similar tools?
I need to debug a web application that uses jQuery to do some fairly complex and messy DOM manipulation. At one point, some of the events that were bound to particular elements, are not fired and simply stop working.
If I had a capability to edit…
![](../../users/profiles/49951.webp)
Jaanus
- 17,268
- 14
- 62
- 102
598
votes
22 answers
UITextField text change event
How can I detect any text changes in a textField? The delegate method shouldChangeCharactersInRange works for something, but it did not fulfill my need exactly. Since until it returns YES, the textField texts are not available to other observer…
![](../../users/profiles/312627.webp)
karim
- 14,810
- 7
- 55
- 92
461
votes
3 answers
How can I trigger an onchange event manually?
I'm setting a date-time textfield value via a calendar widget. Obviously, the calendar widget does something like this :
document.getElementById('datetimetext').value = date_value;
What I want is :
On changing value in the date-time textfield I…
![](../../users/profiles/248941.webp)
CodeTweetie
- 4,865
- 2
- 17
- 23
366
votes
15 answers
Why are only final variables accessible in anonymous class?
a can only be final here. Why? How can I reassign a in onClick() method without keeping it as private member?
private void f(Button b, final int a){
b.addClickHandler(new ClickHandler() {
@Override
public void…
user467871
350
votes
12 answers
Understanding events and event handlers in C#
I understand the purpose of events, especially within the context of creating user interfaces. I think this is the prototype for creating an event:
public void EventName(object sender, EventArgs e);
What do event handlers do, why are they needed,…
![](../../users/profiles/80535.webp)
Levi Campbell
- 5,753
- 7
- 36
- 45
287
votes
10 answers
Difference between e.target and e.currentTarget
I don't understand the difference, they both seem the same but I guess they are not.
Any examples of when to use one or the other would be appreciated.
![](../../users/profiles/272087.webp)
Artemix
- 7,979
- 13
- 45
- 74
285
votes
8 answers
jQuery - Detect value change on hidden input field
I have a hidden text field whose value gets updated via an AJAX response.
When this value changes, I would like to fire an AJAX request. Can anyone advise on how to detect the change?
I have…
![](../../users/profiles/702644.webp)
Ben
- 5,466
- 11
- 48
- 64
263
votes
14 answers
Android: Difference between onInterceptTouchEvent and dispatchTouchEvent?
What is the difference between onInterceptTouchEvent and dispatchTouchEvent in Android?
According to the android developer guide, both methods can be used to intercept a touch event (MotionEvent), but what is the difference?
How do…
![](../../users/profiles/1211663.webp)
Anne Droid
- 3,019
- 3
- 13
- 14
260
votes
2 answers
How can I capture the right-click event in JavaScript?
I want to block the standard context menus, and handle the right-click event manually.
How is this done?
![](../../users/profiles/120888.webp)
Giffyguy
- 17,946
- 30
- 81
- 147
248
votes
3 answers
JavaScript click handler not working as expected inside a for loop
I'm trying to learn JS and got an issue.
I tried many things and googled but all in vain. Following piece of code doesn't work as expected. I should get value of i on click but it always returns 6. I'm pulling my hair out; please help.
for (var i =…
![](../../users/profiles/1849846.webp)
JS-coder
- 2,825
- 2
- 11
- 14
245
votes
1 answer
How to remove a lambda event handler
Possible Duplicates:
Unsubscribe anonymous method in C#
How do I Unregister ‘anonymous’ event handler
I recently discovered that I can use lambdas to create simple event handlers. I could for example subscribe to a click event like…
![](../../users/profiles/39321.webp)
Svish
- 138,188
- 158
- 423
- 589