Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6113109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:49:17+00:00 2026-05-23T14:49:17+00:00

I have a jQuery search script that queries a PHP file then parses the

  • 0

I have a jQuery search script that queries a PHP file then parses the results into an HTML div. When no query is active the text box is automatically selected but when a query is active I want it not to be automatically selected. Currently I have only been able to disable the text box which isn’t what I want. How can I resolve this 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');
        return false;
    });
    $('#type_search').click();
    $('#query').keyup(function(){
        var query=$(this).val();
        var url='/'+type+'/'+query+'/';
        window.location.hash=''+type+'/'+query+'/';
        document.title=$(this).val()+' - My 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();
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:49:17+00:00Added an answer on May 23, 2026 at 2:49 pm

    This is the ‘answer’ version of the comment I just made. If you use $('#query').val().length you can grab the length of the value in the textbox, like so:

    var textlength = $('#query').val().length;
    
    if(textlength <= 0)
        $('#query').focus();
    else
        $('#query').blur();
    

    I don’t think the .blur(); is really required, but it can’t hurt either.


    edit #1: Okay, I assume you have a page where there is a search box and a div-tag where your items are stored (which you do by AJaX). Also I assume that when you then hit F5 (thus reload the whole page) your page will reload and there will already be data in the search box (by PHP or earlier JavaScript statements). Then you can replace your current $('#query').focus();, with the code I posted above.


    edit #2: I’ve just re-read your code, and I think replacing $('#query').focus(); with my code should do the trick exactly like you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jQuery tabbed search script that gets content from a PHP file
I have a PHP and jQuery script that creates search result suggestions from a
I have a jquery script that searches a php file that produces an XML
I have a jQuery tab script that gets content from a PHP file defined
I have some jQuery code. I have called an Ajax function file, file.php, that
I have a Google Instant style search script written in jQuery which queries a
Say I have jquery code like this: html += '<div class=index>' + item.index +
I have this jQuery code that queries an API on a keyup event (via
I need to modify a php search script so that it can handle multiple
I have a jqGrid script like that: jQuery(document).ready(function() { var startDate = $(#startDate).Val(); jQuery(#sandgrid).jqGrid({

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.