I am newbie to java script. I am bit confused about key-press and change event.
Following is sample code
$("input").live('change',function ()
{
Alert("Change event call");
});
/
$("input").live('keypress',function ()
{
Alert("Keypress event call");
});
When exactly Keypress event is call and change event call?
The
changeevent is sent to an element when its value changes. This event is limited to<input>elements,<textarea>boxes and<select>elements. For select boxes, checkboxes, and radio buttons, the event is fired immediately when the user makes a selection with the mouse, but for the other element types the event is deferred until the element loses focus.
The
keypressevent is sent to an element when the browser registers keyboard input. This is similar to thekeydownevent, except in the case of key repeats. If the user presses and holds a key, akeydownevent is triggered once, but separatekeypressevents are triggered for each inserted character. In addition, modifier keys (such as Shift) triggerkeydownevents but notkeypressevents.A
keypressevent handler can be attached to any element, but the event is only sent to the element that has the focus. Focusable elements can vary between browsers, but form elements can always get focus so are reasonable candidates for this event type.
References:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With