javascript - Text input event handler - Stack Overflow

I have a text input and a handler routine testFunc(input.value)testFunc should be called when When a al

I have a text input and a handler routine testFunc(input.value)

testFunc should be called when

  1. When a alphabet key is pressed
  2. when backspace is hit with updated value (i.e when initial input is 1234, when backspace is hit from the end, input should be 123 to the testFunc routine)
  3. If the input is 1234, and backspace is hit from somewhere in the middle i.e 1234, then the testfunc should be called as testFunc(234).
  4. 2, 3 should be similar for DELETE key too.

I tried with onkeypress and onkeyup, but some how testFunc handler routine is not getting with the updated value (or) testFunc routine itself is not getting called.

Can any one let me know how i can resolve this issue or whether there is any existing APIs in Javascript

I have a text input and a handler routine testFunc(input.value)

testFunc should be called when

  1. When a alphabet key is pressed
  2. when backspace is hit with updated value (i.e when initial input is 1234, when backspace is hit from the end, input should be 123 to the testFunc routine)
  3. If the input is 1234, and backspace is hit from somewhere in the middle i.e 1234, then the testfunc should be called as testFunc(234).
  4. 2, 3 should be similar for DELETE key too.

I tried with onkeypress and onkeyup, but some how testFunc handler routine is not getting with the updated value (or) testFunc routine itself is not getting called.

Can any one let me know how i can resolve this issue or whether there is any existing APIs in Javascript

Share Improve this question edited Aug 31, 2011 at 0:00 Flambino 18.8k2 gold badges43 silver badges58 bronze badges asked Aug 30, 2011 at 22:46 progsterprogster 893 silver badges11 bronze badges 1
  • 1 Please show us your code – rlb.usa Commented Aug 30, 2011 at 22:52
Add a ment  | 

2 Answers 2

Reset to default 3

You can use the HTML5 input event, which is fired whenever the input value changes, and fires after the value has changed. In bination with an IE workaround, it's surprisingly patible. See the following answer:

jQuery keyboard events

In which browsers? The following always shows the current value of the input whenever a key is pressed:

  <script type="text/javascript">

  function show(s) {
    document.getElementById('msg').innerHTML = s;
  }

  </script>

  <input type="text" onkeyup="show(this.value);">

  <div id="msg"></div>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745423282a4627062.html

相关推荐

  • javascript - Text input event handler - Stack Overflow

    I have a text input and a handler routine testFunc(input.value)testFunc should be called when When a al

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信