The following codes will not work if I remove the first line (alert()), and it’s obvious that I don’t need it. The form that I bound the events to are generated on the fly with jquery. Please what could be the problem? Thanks.
alert("");
$("#search").autocomplete('func.php');
$("#c_name").autocomplete('func.php');
$("#search").keypress(function(event) {
if (event.which === 13) {
findItem('search');
return false;
}
});
The alert is giving the necessary delay for the forms to get loaded, after which binding an event to an element makes sense. Without the alert statement, the code is getting executed before the form elements can actually load. Try using jquery’s live() function to bind events to elements that are being dynamically loaded. Here is how to use it : http://api.jquery.com/live/