当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - autocomplete list in input text box is not coming

问题描述:

So i am having problem on auto completion feature of jquery. My requirement is to show Json data in auto completion . Json data is coming from java class in jsp page .This code is working fine but nothing is coming in text box as i type something.

This is my jsp page

<%@page import="com.practise.autoComplete.AutoComplete"%>

<%@page import="net.sf.json.JSONObject"%>

<%@page import="net.sf.json.JSON"%>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>

<%@ page import="java.util.*"%>

<%

AutoComplete autoComplete=new AutoComplete();

JSONObject jsonObject=autoComplete.autoComp();

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<script src="./JS/jquery-1.4.2.min.js"></script>

<script src="/JS/jquery.autocomplete.js"></script>

<script>

function lookup(inputString) {

alert("inside lookup");

if (inputString.length == 0) {

$('#suggestions').hide();

} else {

var object=<%=jsonObject%>

var data= JSON.stringify(object);

if (data.length > 0) {

$("#inputauto").autocomplete({

source: data

});

}

}

}

</script>

<head>

<body>

<div>

<form>

<div>

<br /> Enter Name to see autocomplete <input

type="text" size="30" value="" id="inputauto"

onkeyup="lookup(this.value);" />

</div>

</form>

</div>

</body>

</html>

This is my java file

 package com.practise.autoComplete;

import net.sf.json.JSONObject;

public class AutoComplete {

public JSONObject autoComp() {

JSONObject jsonObject = new JSONObject();

jsonObject.put("1", "peter");

jsonObject.put("2", "nadia");

jsonObject.put("3", "jack");

jsonObject.put("4", "areena");

return jsonObject;

}

}

分享给朋友:
您可能感兴趣的文章:
随机阅读: