Tuesday 2 October 2012

Auto Complete Text box using jquery with oracle database and JSP

// siddhu vydyabhushana // 3 comments


Required Files:

  • index.jsp
  • list.jsp
  • jquery.autocomplete.js
  • jquery-1.4.2.min.js
  • style.css




Database:


create a user with name "ex" and password as "ex"create a table as "states" place all your required states in that table



Source Files:

Here i am giving you a link to DOWNLOAD these five files 


How to run:

copy these five files and paste it into C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\yourfolder
run it as http://localhost:8001/index.jsp
type just one character like 'a' then you find all the states starts with "a".


How the source code is working:

See in list.jsp line no.33 you may get one doubt, what is that ‘q‘ right ? in fact we are not sending any parameter with name ‘q’ from the index.jsp but for every keyup in the text box (in index.jsp) jquery will sends each character to the list.jsp in the form of ‘q’ and compares with the values in that list, i mean ‘q’ is the default parameter using by jQuery API.


How to send extra parameters along with that q:

$(‘#country’).autocomplete(“list.jsp”, {extraParams: {state: California }} );
This will generates the internal URL like
……./getdata.jsp?q=ourChar&state=California

Output:

Database:

Table name: states



3 comments: