javascript - Deselecting a text box in jQuery -
javascript - Deselecting a text box in jQuery -
i have 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. have been able disable text box isn't want. how can resolve issue?
my jquery script is:
$(document).ready(function(){ $('[id^=type_]').click(function(){ type=this.id.replace('type_',''); $('[id^=type_]').removeclass('selected'); $('#type_'+type).addclass('selected'); homecoming false; }); $('#type_search').click(); $('#query').keyup(function(){ var query=$(this).val(); var url='/'+type+'/'+query+'/'; window.location.hash=''+type+'/'+query+'/'; document.title=$(this).val()+' - search'; $('#results').show(); if(query==''){ window.location.hash=''; document.title='my search'; $('#results').hide(); } $.ajax({ type:'get', url:url, datatype:'html', beforesend:function(){ $('#query').prop('disabled',true); }, 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(); } $('#query').focus(); });
this 'answer' version of comment made. if utilize $('#query').val().length can grab length of value in textbox, so:
var textlength = $('#query').val().length; if(textlength <= 0) $('#query').focus(); else $('#query').blur(); i don't think .blur(); required, can't wound either.
edit #1: okay, assume have page there search box , div-tag items stored (which ajax). assume when nail f5 (thus reload whole page) page reload , there info in search box (by php or before javascript statements). can replace current $('#query').focus();, code posted above.
edit #2: i've re-read code, , think replacing $('#query').focus(); code should trick want.
javascript jquery html
Comments
Post a Comment