jQuery Form How to - Display what you typed in text field








Question

We would like to know how to display what you typed in text field.

Answer


<!--from   w w w .ja  va 2  s  .com-->
<html>
  <head>
    <script type="text/javascript" src='http://code.jquery.com/jquery-1.5.2.js'></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("input").keypress(function (e) {
                var c = String.fromCharCode(e.which);
                $("p").append($("<span/>")).children(":last").append(document.createTextNode(c));
                $("div").text(e.which);
            });
        });
    </script>
  </head>
  <body>
     <input type="text" />
      <p>Add text - </p>
      <div></div>
  </body>
</html>

The code above is rendered as follows: