I have a page with 2 forms; each form has an input text field;
The value found in the input text of the 1st form must be the same with the value found in the input text of the 2nd form;
When the value changes, the other input text field also modifies its value;
Should I use both onkeyup
and onchange
events?
If not, which one is the right one to use?
I am asking this because it seams that I have 2 post requests, and I think that this is why.
$('input.searchbox').keyup( function(){ $('input.txtfieldsearch').val($('input.searchbox').val()); listViewUpdate(); $('input.txtfieldsearch').trigger("keyup"); }); $('input.txtfieldsearch').keyup( function(){ $('input.searchbox').val($('input.txtfieldsearch').val()); listViewUpdate(); }); $('input.searchbox').change( function(){ $('input.txtfieldsearch').val($('input.searchbox').val()); listViewUpdate(); $('input.txtfieldsearch').trigger("change"); }); $('input.txtfieldsearch').change( function(){ $('input.searchbox').val($('input.txtfieldsearch').val()); listViewUpdate(); });
When user presses a key or combination of different keys, keydown , keypress and keyup are triggered in that order: The keydown event is triggered first when user presses a key. The keyup event is triggered last when user releases a key.
The keyup event occurs when a keyboard key is released. The keyup() method triggers the keyup event, or attaches a function to run when a keyup event occurs.
The keyup() is an inbuilt method in jQuery which is used to trigger the keyup event whenever User releases a key from the keyboard. So, Using keyup() method we can detect if any key is released from the keyboard. Syntax: $(selector).keyup(function) Here selector is the selected element.
The keyup event is fired when a key is released. The keydown and keyup events provide a code indicating which key is pressed, while keypress indicates which character was entered. For example, a lowercase "a" will be reported as 65 by keydown and keyup , but as 97 by keypress .
You can use $.on()
function and attach multiples handlers.
$("#element").on('keyup change', function (){ // Your stuff... });
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