Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery onkeyup method not defined

the onkeyup method is supposedly not defined, however, the method is auto-recommended to me by my ide. When I view the error in chrome dev tools I get the error Uncaught TypeError: Object [object Object] has no method 'onkeyup'. I am using the latest version of jQuery. Here is my code:

    <!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="jquery-1.7.2.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("button").click(function(){
                var str = document.getElementById('txt1').value;
                $.post("addName.php", {q: str});
            });
            $("input").onkeyup(function(){
                var str = document.getElementById('txt1').value;
                $.post("gethint.php", {q: str});
            });
        });
    </script>
</head>
<body>

<h3>Start typing a name in the input field below:</h3>
<form action="">
    First name: <input type="text" id="txt1"/>
</form>
<p>Suggestions: <span id="txtHint"></span></p>
<button> Add Name</button>

</body>
</html>
like image 774
Julian Avatar asked Jun 18 '12 15:06

Julian


People also ask

What is Onkeyup in Javascript?

Definition and UsageThe onkeyup attribute fires when the user releases a key (on the keyboard). Tip: The order of events related to the onkeyup event: onkeydown. onkeypress.

What is Keyup and Keydown in jquery?

Definition and Usagekeydown - The key is on its way down. keypress - The key is pressed down. keyup - The key is released.

What does Keyup return?

The keyup event is fired when a key is released. The keydown and keyup events provide a code indicating which key is pressed, while keypress indicates which character was entered. For example, a lowercase "a" will be reported as 65 by keydown and keyup , but as 97 by keypress .


2 Answers

$("input").on('keyup', function(){
    var str = document.getElementById('txt1').value;
    $.post("gethint.php", {q: str});
});

or

$("input").keyup( function(){
    var str = document.getElementById('txt1').value;
    $.post("gethint.php", {q: str});
});

jQuery has no method name onkeyup

Read more about .keyup() and .on()

like image 97
thecodeparadox Avatar answered Oct 07 '22 05:10

thecodeparadox


The method is:

$("input").keyup(function() {
})
like image 45
cloakedninjas Avatar answered Oct 07 '22 05:10

cloakedninjas