Boa tarde galera,
Alguém poderia me ajudar, dizendo-me o por quê o INPUT fica vazio quando eu clico no NOME do AUTO COMPLETE.
autoSuggestTextbox.jsp:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1
-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery Auto Complete</title>
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
<script type="text/javascript">
function lookup(inputString) {
if (inputString.length == 0) {
$('#suggestions').hide();
} else {
$.post("states.jsp", {
queryString : "" + inputString + ""
}, function(data) {
if (data.length > 0) {
$('#suggestions').show();
$('#autoSuggestionsList').html(data);
}
});
}
}
function fill(thisValue) {
$('#inputString').val(thisValue);
setTimeout("$('#suggestions').hide();", 200);
}
</script>
<style type="text/css">
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;
}
</style>
</head>
<body>
<div>
<form>
<div>
<h3><font color="red">Indian States</states></font></h3>
<br />
Enter India State Name to see autocomplete
<input type="text" size="30" id="inputString" onkeyup = lookup(this.value);;; onblur="fill();" />
</div>
<div class="suggestionsBox" id="suggestions" style="display: none;">
<div class="suggestionList" id="autoSuggestionsList"></div>
</div>
</form>
</div>
</body>
</html>
states.jsp
<%@ page language="java" import="java.sql.*"%>
<%
response.setContentType("text/html");
%>
<%
String str = request.getParameter("queryString");
try {
String connectionURL = "jdbc:mysql://localhost:3306/intranet";
Connection con;
Class.forName("com.mysql.jdbc.Driver");
// Get a Connection to the database
con = DriverManager.getConnection(connectionURL, "root",
"senha");
//Add the data into the database
String sql = "SELECT nome FROM funcionario WHERE nome LIKE '"
+ str +"%'";
Statement stm = con.createStatement();
stm.executeQuery(sql);
ResultSet rs = stm.getResultSet();
while (rs.next()) {
out.println("<li onclick='fill(" + rs.getString("nome")
+ ");'>" + rs.getString("nome") + "</i>");
}
} catch (Exception e) {
out.println("Exception is ;" + e);
e.printStackTrace();
}
%>
Ele tras os dados conforme eu vou digitando o nome, mas quando eu clico no NOME, ele tras o INPUT vazio...
Alguém tem alguma ideia ?
Será que é algo aqui nestas linhas ? pq tras o ID do INPUT.
function fill(thisValue) {
$('#inputString').val(thisValue);
setTimeout("$('#suggestions').hide();", 200);
}
MUITO OBRIGADO !!!!
Aguardo resposta.