Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to check the increase/decrease of letter input in pasting clipboard in jQuery

I can use the keyup() function to check that my user has written something in input.
But what do I do when something pastes there?(Using the mouse, not the keyboard!)

$("#myInput").keyup(function(){
  console.log("increase or decrease now!");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<input id="myInput" />

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The "keyup" event only fires after a (finished) keyboard input, which means it does not fire when you paste something with your mouse. You could instead use the "paste" event, which only fires after you paste something into the input field. But you can combine "keyup" and "paste" like this:

$("#myInput").on("keyup paste", function(){
  console.log("increase or decrease now!");
});

You could also think about the "change" event. This only fires after the input field was changed and loses focus. So, you could actually replace keyup paste by change or combine all of the three to be sure it is fired no matter how the user changes the input field by using keyup paste change.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading