I am trying to learn making ajax calls using jQuery. But I am stuck at a very basic point in using jQuery itself. Follwing is the code I have,
<head>
<script type="text/javascript" src="jquery-1.6.2.js"></script>
<script language="javascript">
$(document).ready(function()
{
alert("Hello World!!!!")
$("#txt1").onkeydown(function(){
alert("Event Fired")
$("#add").load("newjsp.jsp?q="+this.value)
})
})
</script>
</head>
<body>
<form>
Comment: <input type="text" id="txt1"></input>
</form>
<p><p></p></p>
<form id="add">
</form>
</body>
On entering any key in the textbox does not fire the event onkeydown(since there is no alert as “Event Fired”). I do not understand what could be the problem. Please help.
Thanks Rishabh
Use
keydowninstead ofonkeydown..keydown( function(){...} )is a shorthand for.bind("keydown", function){ ... }).See also: http://docs.jquery.com