javascript - Deselect a text box in jQuery after page reload if content is active -
i have google instant style jquery search script queries php file parses results html div. when no query active text box automatically selected when query active want not automatically selected. know possible using .blur();
function, how can make use .blur();
function when query active , page has been reloaded? hope can understand question.
my jquery code is:
$(document).ready(function () { $('[id^=type_]').click(function () { type = this.id.replace('type_', ''); $('[id^=type_]').removeclass('selected'); $('#type_' + type).addclass('selected'); return false; }); $('#query').focus(); if (window.location.hash != "") { var full = window.location.hash.replace('#', ''); var querytype = full.substring(0, full.indexof("/")); $('#type_' + querytype).click(); } else { $('#type_search').click(); } $('#query').keyup(function () { var query = $(this).val(); var url = '/' + type + '/' + query + '/'; window.location.hash = '' + type + '/' + query + '/'; document.title = $(this).val() + ' - search script'; $('#results').show(); if (query == '') { window.location.hash = ''; document.title = 'my search script'; $('#results').hide(); } $.ajax({ type: 'get', url: url, datatype: 'html', success: function (results) { $('#results').html(results); } }); }); if (window.location.hash.indexof('#' + type + '/') == 0) { query = window.location.hash.replace('#' + type + '/', '').replace('/', ''); $('#query').val(decodeuricomponent(query)).keyup(); } });
after reviewing source found suspicion correct. because there 1 text box on page, once blur query one, goes it. can make input node on html page e.g.
<input type="text" style="display:none" id="invisible">
and use code
if ($('#query').val().length) { $('#invisible').focus(); }
and should there :)
Comments
Post a Comment