Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
57
rated 0 times [  59] [ 2]  / answers: 1 / hits: 38936  / 9 Years ago, sun, march 1, 2015, 12:00:00

With



<input type=text onKeyPress=alert(this.value)>


the alert box displays the value in the box, not included the current key depressed.



However, this does not exhibit the same behavior, and I don't know why.



<input type=text onKeyPress=handleInput(this.value)>

function handleInput(value){
alert(value);
}


Added This
http://jsfiddle.net/abalter/adbbb599/6/


More From » onkeypress

 Answers
41

First thing is avoid using js code inside html tags it is a bad practice
, you can use the keyup event to get the content of the input after the user release any pressed key



<input id=input>

<script>
var input = document.getElementById('input');
input.addEventListener('keyup',function(){alert(input.value);});

</script>

[#67619] Friday, February 27, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
moriah

Total Points: 201
Total Questions: 100
Total Answers: 82

Location: Tuvalu
Member since Sun, Sep 4, 2022
2 Years ago
;