How to use onkeyup in javascript?

<script type=text/javascript>
  $(function() {
    $("#echoText").onkeyup(function() {
         $.ajax({
            type: "GET",
            url: $SCRIPT_ROOT + "/echo/",
            contentType: "application/json; charset=utf-8",
            data: { echoValue: $('input[name="echoText"]').val() },
            success: function(data) {
                $('#echoResult').text(data.value);
            }
        });     
    });
  });
</script>
<strong>Enter a value to echo back:</strong>
<input type='text' size='10' id='echoText' name='echoText'>
<button type='button' id='submitBtn' name='submitBtn'>Submit via AJAX</button><br /><br />
<strong><div id='echoResult'></div></strong>

My code does not send the ajax request. Please Help

events don’t work that way. Use jQuery’s on method instead:

    // $("#echoText").onkeyup(function() {
    $("#echoText").on("keyup", function() {

Or without jQuery:

    document.querySelector("#echoText").addEventListener("keyup", function() {
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.