Please help me redo it so that the input is not "alive" (that is, it does not show the number of words IMMEDIATELY, but only after pressing the button). http://pastebin.com/BR2CUJT2

<html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <textarea name="m" cols="48" rows="5" onKeyDown="textCounter(this)" onKeyUp="textCounter(this)"></textarea> <input type="text" id="counter" value="0"> <script type="text/javascript"> function textCounter(el) { document.getElementById("counter").value = el.value.split(" ").length } </script> <br> <button onclick="calc()">Поиск</button> </body> </html> 
  • On input, we hang an "input" event (keydown like) and call the method of the preventDefault event object. This will cancel the standard input behavior, and then do whatever you want with it. - alvoro

1 answer 1

  <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <textarea name="m" id="m" cols="48" rows="5"></textarea> <input type="text" id="counter" value="0"> <script type="text/javascript"> function calc() { var m = document.getElementById("m"); document.getElementById("counter").value = m.value.split(" ").length; } </script> <br> <button onclick="calc()">Поиск</button> </body> </html>