jQuery FAQ autosuggest answer below title as per StackOverflow -


i want have support form use content of 'problem title' field trigger add div below possible answers stackoverflow when submit new question.

to clarify, not want suggested answers presented 'auto-complete' option, want them appear below suggested answer.

the markup in page might like:

<input type="text" value="" placeholder="your problem in brief"> <div id="possibleanswers" class="hidden"> <ul>     <li><a href="#">possible answer 1</a></li>     <li><a href="#">possible answer 2</a></li>     <li><a href="#">possible answer 3</a></li> </ul> </div> 

as user starts type summary of problem div below populate suggested answers.

i managed , running, here's ended with:

var do_live_search = function() {          var stopwords = new array("a","about","an","and","are","as","at","be","by","but","can't","from","how","i","in","is","it","of","on","or","that","the","this","to","was","we","what","when","where","which","with","won't");          var keywords = $("#trigger").val().split(" ");          var clean_keywords = new array();          $.each(keywords,function(i,val){             if(($.trim(val) != "")                 && ($.inarray(val,stopwords)==-1)                 && ($.inarray(val,clean_keywords)==-1)                 && (val.length > 3)                 ){                 clean_keywords.push(val);             }         });          if (clean_keywords.length >= 1) {              var joined_keywords = clean_keywords.join('|');              $.get("/fetch/_search_support_faqs?q="+joined_keywords+"", function(mydata){                  if (mydata != "") {                      $.each(mydata, function(i, item) {                         $('#matchingfaqs ul').append(                             $('<li>').append(                                 $('<a>').attr('href','#faq_'+mydata[i].entry_id).append(mydata[i].title)                         ));                      });                      $('#matchingfaqs').slidedown('slow');                 }              });          }     } 

this triggered using 'type watch' plug-in jquery (https://github.com/dennyferra/typewatch):

var typewatch_options = {         callback:do_live_search,         wait:500,         highlight:true,         capturelength:3     }      // watch key events in search field     $("input#trigger").typewatch(typewatch_options); 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -