0

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.......

3
Contributors
13
Replies
15
Views
6 Years
Discussion Span
Last Post by ypks_destiny
0

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

0

please help me out

Using Jsp You can Achive this
-------------------------------
I will provide the sample code hope it might be useful to ypu.


jsp code
-----------

//LET US SUPPOSE YOU WANT TO GET CITY NAMES IN DATABASE FROM TABLE "branches"

<%
Connection con=DriverManager.getConnection("--set DB parameters---");
Statement st=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
       ResultSet rs = st.executeQuery("SELECT  cityname  FROM branches");


%>



<select name="city">

<%
if(rs.next())
{
rs.beforeFirst();
String city=rs.getString("cityname");//get value from database
while(rs.next())
{
{%>
        <option value="<%= city%>"><%= city%></option>
<%
}
}
else
{%>
        <option>No city in Database   </option>
<%}
%>

</select>

Edited by peter_budo: Keep It Clean - Do wrap your programming code blocks within [code] ... [/code] tags

0

TO : murali.java

You are using Drop down list actually i want it in live search

Edited by ypks_destiny: n/a

0

@peter_budo

Thanks for your kind suggestion....
I know the standared way of getting connection to a jsp page using Hibernate or Persistance .....

I just gave a formal approach how to dispaly the data in a dropdown list.....I just mentioned in short how to to achieve this, reagrdless of other things(getting connectn,using DAO ..etc)..

Iam new to this forum ,not new to java technologies...

0

@murali.java so why do you suggest something that is a bad coding standard if you wouldn't use it? That logic is wrong.

0

@peter_budo,murali.java

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>
<div id='div_city' >
City<input type="text"  name="city" id="city" onkeyup="showState(this.value)"></td>
 <br>
</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'  onselect='text' name='city' value="+rs.getString("cityname")+">"+"<br>";
   }
 buffer=buffer+"</div>";
 response.getWriter().println(buffer);
 %>

This is my actual code...can u help out by fixing the changes...

Edited by ypks_destiny: n/a

0

waiting..........

Keep waiting, because as I already stated I do hate database connectivity done from page view, therefore I'm not touching it.

0

originally posted by peter_budo

it is my part of project to have country-state relation in autocomplete search to take database values by using jsp,HTML

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.