Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery Auto search result is not updating the value to textbox after clicking
    text
    copied!<p>Below code display the list populated from database(DB code is not included). If I click on the search results, then the selected option will not show in textbox. Help please. </p> <p>Below code works fine to show list of options from Database while typing characters. The issue is it will not show the selected drop down option into textbox. </p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;jQuery Auto Complete&lt;/title&gt; &lt;script src="jquery/jquery.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; function lookup(inputString) { if(inputString.length == 0) { $('#suggestions').hide(); } else { $.post("states.jsp", {queryString: ""+inputString+""}, function(data){ if(data.length &gt;0) { $('#suggestions').show(); $('#autoSuggestionsList').html(data); } }); } } function fill(thisValue) { $('#inputString').val(thisValue); setTimeout("$('#suggestions').hide();", 200); } &lt;/script&gt; &lt;style type="text/css"&gt; body { font-family: Helvetica; font-size: 13px; color: #000; } h3 { margin: 0px; padding: 0px; } .suggestionsBox { position: relative; left: 260px; margin: 0px 0px 0px 0px; width: 200px; background-color: #7845DD; -moz-border-radius: 7px; -webkit-border-radius: 7px; border: 2px solid #000; color: #fff; } .suggestionList { margin: 0px; padding: 0px; } .suggestionList li { margin: 0px 0px 3px 0px; padding: 3px; cursor: pointer; } .suggestionList li:hover { background-color: #DD45CD; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div&gt; &lt;form&gt; &lt;div&gt; &lt;h3&gt;&lt;font color="red"&gt;Indian States&lt;/states&gt;&lt;/font&gt;&lt;/h3&gt; &lt;br /&gt; Enter India State Name to see autocomplete &lt;input type="text" size="30" value="" id="inputString" onkeyup="lookup(this.value);" onblur="fill();" /&gt; &lt;/div&gt; &lt;div class="suggestionsBox" id="suggestions" style="display: none;"&gt; &lt;div class="suggestionList" id="autoSuggestionsList"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/form&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; &lt;% String name=request.getParameter("queryString"); try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance(); Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost", "user", "password"); Statement st=con.createStatement(); //Add the data into the database String sql = "SELECT EMP_EMPLOYEE_ID, EMP_FNAME, EMP_LNAME FROM UAP_EMPLOYEE where EMP_FNAME LIKE '%"+name+"%' OR EMP_LNAME LIKE '%"+name+"%';"; Statement stm = con.createStatement(); stm.executeQuery(sql); ResultSet rs= stm.getResultSet(); while (rs.next ()){ out.println("&lt;li onclick='fill("+rs.getString("EMP_FNAME")+");&gt;"+rs.getString("EMP_FNAME")+" &lt;/i&gt;"); }}catch(Exception e){ out.println("Exception is ;"+e); } %&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload