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.......
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
please please help me out I think we have to use AJAX
please help me out
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>
TO : murali.java
You are using Drop down list actually i want it in live search
@murali.java being your boss I would make sure that you will not be offered new contract when your current expire. :@ making db connection from page. BAD! BAD! BAD! At least do it from servlet if you do not know Persistence or Hibernate
@ypks_destiny have look on Ajax Asynchronous call, something like this article should be helpful
@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...
@murali.java so why do you suggest something that is a bad coding standard if you wouldn't use it? That logic is wrong.
@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...
plz help me out
waiting..........
waiting..........
Keep waiting, because as I already stated I do hate database connectivity done from page view, therefore I'm not touching it.
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
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.