
Hi, I am doing a project on invoice making, I am unable to make code for the billing, I have a n jsp page "invc.jsp", here in this page i need to get the items from the data base with respect to the item code, I am taking item code in a drop down list, and the item codes should be sorted by the most selected items order, I want to add two or more items for the billing, and the select items are added to the "bill.jsp" page with total amount to be payable,and the selected item quantity should be updated in the data base, so please help me in this,
<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>;
<script type="text/javascript>
function generatenew(){
document.abc.code1.style.visibility="visible";
document.abc.type1.style.visibility="visible";
document.abc.quantity1.style.visibility="visible";
}
</script>
<%
String data1 = request.getParameter("code1");
String data2 = request.getParameter("type1");
String data3 = request.getParameter("quantity1");
%>
<form method="post" name='invcform' action="invoice.do">;
<table cellpadding='2' cellspacing='2' border="0" bgcolor="#E9E9E9" colspan="0" width="500" align="center">
<tr><td></td></tr>
<tr><td>Customer Name:</td><td><input type="text" name="name" value="" size=25></td>
<td>Number:</td><td><input type="text" name="no" value="" size=20></td></tr>;
<tr><td>Address</td><td><textarea rows="2" cols="20" name="add"></textarea></td></tr>
<tr><td><br></td></tr>
<tr><td>Item Code:</td><td><select name='code' onchange="showState(this.value)"><br>
<option value="none">Select</option>
<option value="code"></option></select> <input type="text" style="visibility:hidden" name="code1" size="10"></td></tr>
</table>

Here is a jsp application, where user is allowed to select the item code from the dropdown whose values have been retrieved from the database. On selecting particular item code, the name and price linked with that code will get displayed into the textboxes.
1)items.jsp:
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<html>
<head>
<script type="text/javascript">
function showData(){
xmlHttp=GetXmlHttpObject()
var code=document.getElementById("code").value;
var url="price.jsp";
url=url+"?code="+code;
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
var showdata = xmlHttp.responseText;
var strar = showdata.split(":");
if(strar.length>1)
{
var strname = strar[1];
document.getElementById("name").value= strar[1];
document.getElementById("price").value= strar[2];
}
}
}
function GetXmlHttpObject(){
var xmlHttp=null;
try{
xmlHttp=new XMLHttpRequest();
}
catch(e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>
</head>
<body>
<select id='code' onchange="showData()">
<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("itemCode")%>"><%=rs.getString("itemCode")%></option>
<%
}
%>
</select>
<br>
<div id='item'>
<table>
<tr><td>Item Name:</td><td><input type="text" id="name" name="name"></td></tr>
<tr><td>Price:</td><td><input type="text" id="price" name="price"></td></tr>
</table
</div>
</body>
</html>
2)price.jsp:
<%@page language="java" import ="java.sql.*" %>
<%
String code=request.getParameter("code");
String buffer="";
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 code='"+code+"' ");
while(rs.next()){
buffer=":"+rs.getString("itemName")+":"+rs.getString("itemPrice");
}
out.println(buffer);
%>