-3

Simple code:

<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

    <script type="text/javascript" src="http://code.jquery.com/jquery-    
     latest.min.js"></script>
    <script type="text/javascript">
        $("#target").keyup(function() {
            alert("Handler for .keyup() called.");
        });
    </script>
</head>

<body>
    <form>
        <input id="target" type="text">
    </form>
</body>

</html>

I can type in the input field, but no alert is shown. I have also tried this in Chrome and Mozilla.

unclemeat
  • 5,029
  • 5
  • 28
  • 52
Ondrej Tokar
  • 4,898
  • 8
  • 53
  • 103

1 Answers1

1

You need to run the keyup function after the document finishes loading

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

  <script type="text/javascript" src="http://code.jquery.com/jquery-    
 latest.min.js"></script>
  <script type="text/javascript">
    $(document).ready(function() {
      $("#target").keyup(function() {
        alert("Handler for .keyup() called.");
      });
    });
  </script>
</head>

<body>
  <form>
    <input id="target" type="text">
  </form>
</body>

</html>
Han
  • 449
  • 5
  • 18