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 6772631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:34:18+00:00 2026-05-26T15:34:18+00:00

Here am sending contents of the textbox with class searcher using keyup event by

  • 0

Here am sending contents of the textbox with class searcher using keyup event by ajax. I wanted not to send ajax request if the textbox with class searcher is empty and clear the content of a div with id sub_cont. but i couldn’t do it.

anyone help with pointing out where am wrong

thanks

$(".searcher").keyup(function(){

        if($('.searcher').val == "")
        {
        $('#sub_cont').fadeOut(1500);
        }
        else{

        //show the loading bar
        showLoader();
        $('#sub_cont').fadeIn(1500);
        $("#content #sub_cont").load("main/search.php?val=" + $("#search").val(), hideLoader());
    }

    });
  • 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-26T15:34:19+00:00Added an answer on May 26, 2026 at 3:34 pm
    // cache commonly used selectors (but not in a global scope, please).
    var sub_cont = $("#sub_cont");
    $(".searcher").keyup(function(){
        // check if the value of the input is empty or whitespace
        // you don't need to check the length of the string or even 
        // bother checking if it is `== ""` as an empty string already
        // evaluates to false.
        if(!$.trim(this.value)){
            // stop any existing animations before fading out
            // so we don't have ourselves a long queue of animations.
            sub_cont.stop().fadeOut(1500);
        }
        else{
            showLoader();
            // **Note: While `$.fn.load` is certainly the easiest way to do it,
            // other methods, such as $.fn.get are much more robust.**
            // (see my comments in the body of the answer for why)
            // Use the `data` parameter to make sure your values are encoded and
            // concatenated properly. This also allows for much more maintainable 
            // code
            sub_cont.load("main/search.php", {"val": this.value}, function(){
                 hideLoader();
                 sub_cont.stop().fadeIn(1500);
            });
        }
    });
    

    You should use $.get instead of $.fn.load here for several reasons:

    1. This “autocomplete” function will be called every time a key is pressed. Using $.get you can cache the jXHR object and abort() the previous ajax request before sending a new one.
    2. Errors happen. load gives you no escape hatch if there is an error whereas get does.
    3. By implementing these suggestions yourself by reading the jQuery docs on $.get you’ll learn a lot more about jQuery and javascript. :-p
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have issue with sending AJAX body request using jQuery CORS with custom Content-type.
I am sending HTTP GET request and receiving data here: ssize_t numBytes = recvfrom(sock,
From My Previous question sending request to apple - from iphone custom application Here,
I was having trouble sending up a url containing accent characters using IE. Here's
I got some sample code from the net here: http://www.javadb.com/sending-a-post-request-with-parameters-from-a-java-class That works fine. It
Javascript/jQuery newbie here. My webserver is sending the contents of a directory tree as
I've downloaded a sample application sending email silverlight application here. via gmail. But I
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`
I am using the following code to send out a Multipart/Alternative HTML and Plain

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.