Reputation: 691
I have a jquerymobile site. One of the pages has a search box with a .keyup event.
When you start typing or press enter it triggers this event.
If I get to this page from my homepage the triggers don't work. If I'm on this page and i reload the page then the trigger works. The site is all one file with different DIVs as pages.
The only way it works is if I reload the page first.
Any ideas? Thanks This is loaded in a header.
$(document).ready(function() {
$.ajaxSetup ({
cache: false
});
$("#gsearch").keyup(function(event) {
clearTimeout($.data(this, 'timer'));
var wait = setTimeout(gsearch, 600);
$(this).data('timer', wait);
});
function gsearch() {
var len = 0;
var searchdata = '';
searchdata = $("#gsearch").val();
len = searchdata.length;
if ( len >= 2 ) {
//$("#gtemp").html("<center><img src='ajax-loader.gif'></center>");
//$.mobile.pageLoading();
$.ajax({
// code here
}
});
}
}
This is the search box
<center>
<div align="center" style="padding:5px; text-align:center;">
<input type="search" id="gsearch" value="" />
</div>
</center>
<div id="googleres">
Upvotes: 3
Views: 13401
Reputation: 25188
Works fine here:
.keyup
works fine, your code inside must be wrong
if you're dynamically loading the search box you need to use:
$("#gsearch").live("keyup", function(event) {
//run code
}
Upvotes: 9