combox

combox

i have one table in database item master..if i select one item throug combo box than other combobox show item price only select item name... how i can implement through jsp in a single jsp page.

View Answers

April 3, 2012 at 5:27 PM

We have used table item having fields itemId, itemName, itemPrice.

1)items.jsp:

<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<html>
<head>
<script language="javascript" type="text/javascript">
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= "price.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("item").innerHTML=xmlHttp.responseText
}
}
</script>
</head>
<body>
<select name='country' onchange="showState(this.value)">
<option value="none">Select</option>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root","root";);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from item");
while(rs.next()){
%>
<option value="<%=rs.getString("itemName")%>"><%=rs.getString("itemName")%></option>
<%
}
%>
</select>
<br>
<div id='item'>
<select name='item' >
<option value='-1'></option>
</select>
</div>
</body>
</html>

2)price.jsp:

<%@page language="java" import ="java.sql.*" %>
<%
String itemname=request.getParameter("count");
String buffer="<select name='state'><option value='-1'>Select</option>";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root","root";);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from item where itemName='"+itemname+"' ");
while(rs.next()){
buffer=buffer+"<option value='"+rs.getString("itemPrice")+"'>"+rs.getString("itemPrice")+"</option>";
}
buffer=buffer+"</select>";
response.getWriter().println(buffer);
%>

April 3, 2012 at 10:03 PM

i want to answer in single page means only one jsp page...in above code you mention two .jsp file but i have one .jsp file as well as one database table so tell me appropriate solution for that....

Ads









Related Tutorials/Questions & Answers:
combox
combox   i have one table in database item master..if i select one item throug combo box than other combobox show item price only select item name... how i can implement through jsp in a single jsp page.   We have used
ModuleNotFoundError: No module named 'combox'
ModuleNotFoundError: No module named 'combox'  Hi, My Python... 'combox' How to remove the ModuleNotFoundError: No module named 'combox'... to install padas library. You can install combox python with following command
Advertisements
I want to Populate ComBobox value from database that combox is Itemrenderer of DataGrid.
I want to Populate ComBobox value from database that combox is Itemrenderer of DataGrid.  I want to Populate ComBobox value from database that combox is Itemrenderer of DataGrid
create a table in access2007 from gui application using textfields and combox
how can retrive value from combo box in servlet?
how can retrive value from combo box in servlet?  i have a jsp page with combobox. And i want to get value from combox to servlet
Nitobi ComboBox V3
. Ajax Architecture: Enables the combox to find the data fast with low overhead

Ads