code_junkie

How to get the new value of an HTML input after a keypress has modified it?

Nov 11th, 2011
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. <input type="text" id="foo" value="bar">
  2.  
  3. function showMe(e) {
  4. // i am spammy!
  5. alert(e.value);
  6. }
  7. ....
  8. <input type="text" id="foo" value="bar" onkeyup="showMe(this)" />
  9.  
  10. <html>
  11. <head>
  12. <script>
  13. function callme(field) {
  14. alert("field:" + field.value);
  15. }
  16. </script>
  17. </head>
  18. <body>
  19. <form name="f1">
  20. <input type="text" onkeyup="callme(this);" name="text1">
  21. </form>
  22. </body>
  23. </html>
  24.  
  25. <html>
  26. <head>
  27. <script type="text/javascript" src="jquery.js"></script>
  28. <script type="text/javascript">
  29. $(document).ready(function() {
  30. $('#foo').keyup(function(e) {
  31. var v = $('#foo').val();
  32. $('#debug').val(v);
  33. })
  34. });
  35. </script>
  36. </head>
  37. <body>
  38. <form>
  39. <input type="text" id="foo" value="bar"><br>
  40. <textarea id="debug"></textarea>
  41. </form>
  42. </body>
  43. </html>
Add Comment
Please, Sign In to add comment