Youss
Youss

Reputation: 4232

Clear search results on keyup

I have a script which allows to display bing search results: JsFiddle

If you type a letter you will see the results for this letter. If you then do backspace and then type the same letter you will not get any results, so:

  1. type letter = results
  2. backspace = remove results
  3. typing same (first) letter = NO results

This happens becouse I set a code to take clear the results if the val of input is empty like this:

$('#searchbox').live('keyup', function(){

var teq = $('#searchbox').val();

     doSearch(teq); 


    if (teq == '')
    {
        clearResults();
    }

}); 

So by clearing the results like this I'm actually causing a problem the same time becouse there are no results for the second time a same query is made. So my question is: How can I clear the results in a way that I would still be able to do the same query? Which means:

  1. type letter = results
  2. backspace = remove results
  3. typing same (first) letter = results

Upvotes: 1

Views: 690

Answers (1)

Simon
Simon

Reputation: 381

You have in your code this comment:

// if our search is not blank AND is not what we last searched for

therefore I changed the statement

if ((search!='') && (search!=lastSearch))

to:

if ((search!=''))

You can see the result: http://jsfiddle.net/F9T7E/10/

Upvotes: 1

Related Questions