javascript - Remove suggestions when inputfield is not focused -


i'm creating auto complete search box. suggestions have disappear when user clicks outside search field.

the form input field:

<input type="text" name="naam_textbox" id="naam_textbox" class="field" autocomplete="off" onkeyup="suggest(this.value, 'naam');" onblur="fill();" /> 

the javascript code:

function suggest(inputstring, veld){ if(veld == "naam") {     if(inputstring.length < 2) {         $('#suggestions_naam').fadeout();     } else {     $('#naam_textbox').addclass('load');         var dropdown = $( '<div class="suggestionsbox" id="suggestions_naam" style="display: none;"><div class="suggestionlist" id="suggestionslist_naam"> &nbsp; </div></div>' );         if (inserted_naam == 0) {             dropdown.insertafter( "#naam_textbox" );             inserted_naam = 1;         }         $.post("includes/homepage/autosuggest_naam.php", {querystring: ""+inputstring+""}, function(data){             if(data.length >0) {                 $('#suggestions_naam').fadein();                 $('#suggestionslist_naam').html(data);                 $('#naam_textbox').removeclass('load')             }         });     } } }  function fill(thisvalue, veld) {     if(veld == "naam") {         $('#naam_textbox').val(thisvalue);         settimeout("$('#suggestions_naam').fadeout();", 60);     } } 

"fadeout" makes suggestions go away whenever inputstring less 2 characters, or when 1 of suggestions selected.

i need fadeout whenever clicks outside input field (lose focus) or doesn't select suggestion. make more clear, image:

suggestions should go away when user clicks on red dot

the suggestions should go away when user clicks somewhere near red dot example. can't work, please?

here cause of issue,

onblur="fill();" //no parameters 

whereas method

function fill(thisvalue, veld) {   //2parameters     if(veld == "naam") {         $('#naam_textbox').val(thisvalue);         settimeout("$('#suggestions_naam').fadeout();", 60);     } } 

missing pass parameters , therefore not working.

so change

onblur = "fill(this.value, 'naam')" 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -