I want a text field which should have database values....(like dropdown list) from that list i can select text which is in database...

Can any one help me out its very urgent.......

once see www.justdial.com under "City" text box i want exactly like that ...i also want to match the values like that...

can any one please help me out.its urgent

TO : pritaeas

Thanks for replying...but actually i want only by using Ajax,JSp,MySql,Html........

Please help me out its urgent

jQuery uses AJAX to get the required values, so what is the issue.

city.JSP

<%@page import="java.sql.*"%>
 <html>
 <head>

 <script language="javascript" type="text/javascript">
      var xmlHttp
      var xmlHttp
      function showState(str){
      if (typeof XMLHttpRequest != "undefined"){
      xmlHttp= new XMLHttpRequest();
      }
      else if (window.ActiveXObject){
      xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
      }
      if (xmlHttp==null){
      alert("Browser does not support XMLHTTP Request")
      return;
      }
      var url="div_city.jsp";
      url +="?count=" +str;
      xmlHttp.onreadystatechange = stateChange;
      xmlHttp.open("GET", url, true);
      xmlHttp.send(null);
      }

      function stateChange(){
      if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
      document.getElementById("div_city").innerHTML=xmlHttp.responseText
      }
      }


      </script>
 </head>
 <body>
 
City<input type="text" name="city" id="city" onkeyup="showState(this.value)"></td>
 <br>
 <div id='div_city'>
 </div>
   </body></center>
 </html>

div_city.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="java.sql.*"%>
 <%
 String name=request.getParameter("count");
 String buffer="<div>";
 Class.forName("com.mysql.jdbc.Driver").newInstance();
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Prashanth","root","");
 Statement stmt = con.createStatement();
 ResultSet rs = stmt.executeQuery("Select cityname from city where cityname LIKE '%"+name+"%'");
   while(rs.next()){
   buffer=buffer+"<input type='text' name='city' value="+rs.getString("cityname")+">"+"<br>";
   }
 buffer=buffer+"</div>";
 response.getWriter().println(buffer);
 %>

This is my actual code but its not working.......

What is the problem with this code ? What error do you get, or what doesn't it do ?

It doesnt give errors but live search is not happening...for example if i type "a" letter in text field it searches the database and display 5 different text fields and i am onable to select in my city field....

I think the input's are a weird choice for showing your possibilities. I think a normal div containing links would be a more sensible choice. You'll need to add some javascript to each link, so when it is clicked, it will be copied to main editbox. Have a look at this demo.

Re: ajax live search
I think the input's are a weird choice for showing your possibilities. I think a normal div containing links would be a more sensible choice. You'll need to add some javascript to each link, so when it is clicked, it will be copied to main editbox. Have a look at this demo.

that demo you gave was a good one....but it is not taking values from database .....I want the values to be taken from database.....

There are a lot of examples in this forum on how to do that. Just search for XMLHttpRequest.

There are a lot of examples in this forum on how to do that. Just search for XMLHttpRequest.

i tried each and every one but i couldn't find it...all of them are in dropdown list only i want it in text field search

Just take the communication part and adjust it to what you need.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.