Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

input change event on enter key not working in IE

$("#inputBoxWidth").change(function() {
  var curValue = $("#inputBoxWidth").val();
  alert(curValue);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
  <input type="text" id="inputBoxWidth">
</form>

When I press enter key in all browsers I get the alert function working except IE. In IE I have to click outside of the input element so the input looses focus and than it works. I need IE behave the same as other browser when pressing enter the alert popup shows up with the current value. How to do achieve that?

like image 382
soonic Avatar asked Jan 18 '26 03:01

soonic


1 Answers

What you can do is use the keyup event.

Which gives you :

$("#inputBoxWidth").keyup(function() { // Your code });

Don't use the keydown event because if you want to get the value of the input it will give the value before the key was pressed.

:)

like image 103
clota974 Avatar answered Jan 20 '26 19:01

clota974



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!