my code...
newpo.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.*" %>
<%@ page import="java.io.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script language="JavaScript">
<!--
var months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var days = new Array("S", "M", "T", "W", "T", "F", "S");
today = new getToday();
var element_id;
function getDays(month, year)
{
// Test for leap year when February is selected.
if (1 == month)
return ((0 == year % 4) && (0 != (year % 100))) ||
(0 == year % 400) ? 29 : 28;
else
return daysInMonth[month];
}
function getToday()
{
// Generate today's date.
this.now = new Date();
this.year = this.now.getFullYear() ; // Returned year XXXX
this.month = this.now.getMonth();
this.day = this.now.getDate();
}
function newCalendar()
{
var parseYear = parseInt(document.all.year [document.all.year.selectedIndex].text);
var newCal = new Date(parseYear , document.all.month.selectedIndex, 1);
var day = -1;
var startDay = newCal.getDay();
var daily = 0;
today = new getToday(); // 1st call
if ((today.year == newCal.getFullYear() ) && (today.month == newCal.getMonth()))
day = today.day;
// Cache the calendar table's tBody section, dayList.
var tableCal = document.all.calendar.tBodies.dayList;
var intDaysInMonth =
getDays(newCal.getMonth(), newCal.getFullYear() );
for (var intWeek = 0; intWeek < tableCal.rows.length; intWeek++)
for (var intDay = 0;
intDay < tableCal.rows[intWeek].cells.length;
intDay++)
{
var cell = tableCal.rows[intWeek].cells[intDay];
// Start counting days.
if ((intDay == startDay) && (0 == daily))
daily = 1;
// Highlight the current day.
cell.style.color = (day == daily) ? "red" : "";
if(day == daily)
{
document.all.todayday.innerText= "Today: " + day + "/" +
(newCal.getMonth()+1) + "/" + newCal.getFullYear() ;
}
// Output the day number into the cell.
if ((daily > 0) && (daily <= intDaysInMonth))
cell.innerText = daily++;
else
cell.innerText = "";
}
}
function getTodayDay()
{
document.all[element_id].value = today.day + "/" + (today.month+1) +
"/" + today.year;
//document.all.calendar.style.visibility="hidden";
document.all.calendar.style.display="none";
document.all.year.selectedIndex =100;
document.all.month.selectedIndex = today.month;
}
function getDate()
{
// This code executes when the user clicks on a day
// in the calendar.
if ("TD" == event.srcElement.tagName)
// Test whether day is valid.
if ("" != event.srcElement.innerText)
{
var mn = document.all.month.selectedIndex+1;
var Year = document.all.year [document.all.year.selectedIndex].text;
document.all[element_id].value=event.srcElement.innerText+"/"+mn +"/" +Year;
//document.all.calendar.style.visibility="hidden";
document.all.calendar.style.display="none";
}
}
function GetBodyOffsetX(el_name, shift)
{
var x;
var y;
x = 0;
y = 0;
var elem = document.all[el_name];
do
{
x += elem.offsetLeft;
y += elem.offsetTop;
if (elem.tagName == "BODY")
break;
elem = elem.offsetParent;
} while (1 > 0);
shift[0] = x;
shift[1] = y;
return x;
}
function SetCalendarOnElement(el_name)
{
if (el_name=="")
el_name = element_id;
var shift = new Array(2);
GetBodyOffsetX(el_name, shift);
document.all.calendar.style.pixelLeft = shift[0]; // - document.all.calendar.offsetLeft;
document.all.calendar.style.pixelTop = shift[1] + 25 ;
}
function ShowCalendar(elem_name)
{
if (elem_name=="")
elem_name = element_id;
element_id = elem_name; // element_id is global variable
newCalendar();
SetCalendarOnElement(element_id);
//document.all.calendar.style.visibility = "visible";
document.all.calendar.style.display="inline";
}
function HideCalendar()
{
//document.all.calendar.style.visibility="hidden";
document.all.calendar.style.display="none";
}
function toggleCalendar(elem_name)
{
//if (document.all.calendar.style.visibility == "hidden")
if(document.all.calendar.style.display=="none")
ShowCalendar(elem_name);
else
HideCalendar();
}
-->
</script>
<style>
.today {COLOR: black; FONT-FAMILY: sans-serif; FONT-SIZE: 10pt; FONT-WEIGHT: bold}
.days {COLOR: navy; FONT-FAMILY: sans-serif; FONT-SIZE: 10pt; FONT-WEIGHT: bold; TEXT-ALIGN: center}
.dates {COLOR: black; FONT-FAMILY: sans-serif; FONT-SIZE: 10pt}
</style>
<SCRIPT language="javascript">
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[1].cells.length;
for(var i=0; i<colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[1].cells[i].innerHTML;
newcell.childNodes[0].value = "";
newcell.childNodes[0].value = "";
newcell.childNodes[0].value = "";
newcell.childNodes[0].value = "";
}
}
function deleteRow()
{
var ptable = document.getElementById('dataTable');
var lastElement = ptable.rows.length;
if (lastElement > 1) ptable.deleteRow(lastElement - 1);
if(document.getElementById("psize").value>1)
{
document.getElementById("psize").value =
document.getElementById("psize").value-1;
}
}
</SCRIPT>
</head>
<body style="font-family: verdana; font-size: small; ">
<table style="visibility: visible" width="100%" >
<tr>
<td>
<%@include file="header.html" %>
</td>
</tr>
<tr>
<td >
<table border="0" cellpadding="0" cellspacing="0" width="100%" >
<tr>
<td height="28" width="10%" bgcolor="#699BC5" align="center"><label style="color: white; font-family: verdana"><b>New Purchase Order</b></label></td>
</tr>
</table>
<br>
<table style="visibility: visible">
<script>
function hello(){
var w = document.form.sel.selectedIndex;
var value = document.form.sel.options[w].text;
window.location.replace("newpo.jsp?st="+value);
}
</script>
<tr><td><table >
<form name="form" method="post">
<tr>
<td>
<label>Vendor Name</label></td><td> :</td>
<td colspan="4">
<select name="sel" onchange="hello();">
<option value="-1"> --select-- </option>
<%
Class.forName("com.mysql.jdbc.Driver");
String connectionURL = "jdbc:
mysql://localhost:3306/material";;
Connection connection = DriverManager.getConnection(connectionURL, "root", "freena");
PreparedStatement psmnt = connection.prepareStatement("select * from mstvendor ");
ResultSet results = psmnt.executeQuery();
while (results.next()) {
String name = results.getString(2);
%>
<option value="<%= name%>"> <% out.println(name);%> </option>
<%}
results.close();
psmnt.close();
%>
</select></td></tr>
</form></table></td></tr>
<%
String str = request.getParameter("st");
Connection conn;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:
mysql://localhost:3306/material";, "root", "freena");
Statement st = conn.createStatement();
ResultSet rs1 = st.executeQuery("Select * from mstvendor where VendorName='" + str + "'");
while (rs1.next()) {
String VendorId = rs1.getString(1);
String VendorName = rs1.getString(2);
String VendorAddress = rs1.getString(3);
String VendorNumber = rs1.getString(4);
String VendorCity = rs1.getString(5);
String VendorState = rs1.getString(6);
String VendorCountry = rs1.getString(7);
String VendorPostalcode = rs1.getString(8);
String VendorEmail = rs1.getString(9);
String ContactPerson = rs1.getString(12);
%>
<form method="post" action="newpo1.jsp" name="frm" >
<tr><td>
<table border="1" bgcolor="#F0F9FF" style="border-color: #cccccc; border-style: solid" cellpadding="00" cellspacing="00" width="100%" >
<tr style="border-color: transparent" >
<td style="visibility: visible">
<label>Vendor Name </label>
</td>
<td> :</td>
<td>
<input type="text" style="border: transparent" name="VendorName" value="<%=VendorName%>"/>
</td>
<td >
<label>Vendor Id</label>
</td>
<td> :</td>
<td><input type="text" style="border: transparent" name="VendorId" value="<%=VendorId%>" />
</td>
</tr>
<tr style="border-color: transparent" >
<td>
<label>Vendor Address</label>
</td>
<td> :</td>
<td>
<input type="text" style="border: transparent" name="VendorAddress" value="<%=VendorAddress%>"/>
</td>
<td >
<label>City </label>
</td><td> :</td>
<td><input type="text" style="border: transparent" name="VendorCity" value="<%=VendorCity%>" />
</td>
</tr>
<tr style="border-color: transparent" >
<td>
<label>State</label>
</td><td> :</td>
<td>
<input type="text" style="border: transparent; visibility: visible" name="VendorState" value="<%=VendorState%>" />
</td>
<td >
<label>Country </label></td><td> :</td>
<td>
<input type="text" style="border: transparent" name="VendorCountry" value="<%=VendorCountry%>" />
</td>
<td>
<label>Postalcode</label></td><td> :</td>
<td>
<input type="text" style="border: transparent" name="VendorPostalcode" value="<%=VendorPostalcode%>" />
</td>
</tr>
<tr style="border-color: transparent" >
<td >
<label>Email </label></td><td> :</td>
<td>
<input type="text" style="border: transparent" name="VendorEmail" value="<%=VendorEmail%>" />
</td>
<td>
<label>Contact Number </label></td><td> :</td><td>
<input type="text" style="border: transparent" name="VendorNumber" value="<%=VendorNumber%>" />
</td>
</tr>
<tr style="border-color: transparent" >
<td ><label >Contact Person </label></td> <td> :</td><td>
<input type="text" style="border: transparent" name="ContactPerson" value="<%=ContactPerson%>" /></td>
</tr>
<%
}
%>
</table></td></tr>
<tr><td>
<table border="1" bgcolor="#F0F9FF" style="border-color: #cccccc; border-style: solid" cellpadding="00" cellspacing="00" width="100%" >
<tr style="border-color: transparent" >
<td><label >Order Date </label></td> <td> :</td>
<td>
<INPUT id=MyDate name=PoDate size=15 value="DD/MM/YYYY" onfocus="toggleCalendar('MyDate')">
<TABLE bgColor=#ffffff border=1 cellPadding=0 cellSpacing=3 id=calendar style="DISPLAY: none; POSITION: absolute; Z-INDEX: 4">
<TBODY>
<TR>
<TD colSpan=7 vAlign=center>
<!-- Month combo box -->
<SELECT id=month onchange=newCalendar()>
<SCRIPT language=JavaScript>
// Output months into the document.
// Select current month.
for (var intLoop = 0; intLoop < months.length; intLoop++)
document.write("<OPTION " + (today.month == intLoop ? "Selected" : "") + ">" + months[intLoop]);
</SCRIPT>
</SELECT>
<!-- Year combo box -->
<SELECT id=year onchange=newCalendar()>
<SCRIPT language=JavaScript>
// Output years into the document.
// Select current year.
for (var intLoop = 1900; intLoop < 2028; intLoop++)
document.write("<OPTION " + (today.year == intLoop ? "Selected" : "") + ">" + intLoop);
</SCRIPT>
</SELECT>
</TD>
</TR>
<TR class=days>
<!-- Generate column for each day. -->
<SCRIPT language=JavaScript>
// Output days.
for (var intLoop = 0; intLoop < days.length; intLoop++)
document.write("<TD>" + days[intLoop] + "</TD>");
</SCRIPT>
</TR>
<TBODY class=dates id=dayList onclick="getDate('')" vAlign=center>
<!-- Generate grid for individual days. -->
<SCRIPT language=JavaScript>
for (var intWeeks = 0; intWeeks < 6; intWeeks++)
{
document.write("<TR>");
for (var intDays = 0; intDays < days.length; intDays++)
document.write("<TD></TD>");
document.write("</TR>");
}
</SCRIPT>
<!-- Generate today day. --></TBODY>
<TBODY>
<TR>
<TD class=today colSpan=5 id=todayday onclick=getTodayDay()></TD>
<TD align=right colSpan=2><A href="javascript:HideCalendar();"><SPAN style="COLOR: black; FONT-SIZE: 10px"><B>Hide</B></SPAN></A></TD>
</TR>
</TBODY>
</TABLE>
</td>
<td>
<label> PO Status </label>
</td> <td> :</td>
<td>
<select name="POStatus" onchange="document.getElementById('id2').value=this.options[this.selectedIndex].text" >
<option id="pending" >Pending</option>
<option id="approved">Approved</option>
<option id="unapproved">Unapproved</option>
<option id="close">Close</option>
</select>
</td>
<td><input type="text" id="id2" name="POStatus" style="border: transparent; visibility: hidden" /></td>
</tr>
<tr style="border-color: transparent">
<td>
<label>Purchase Agent</label>
</td> <td> :</td>
<td>
<input type="text" name="POAgent" value=""/>
</td>
<td>
<label>Purchase Term </label>
</td> <td> :</td>
<td>
<input type="text" name="POTerm" value=""/>
</td>
</tr>
</table></td></tr>
<tr><td>
<input type="hidden" name="psize" id="psize">
<table id="dataTable" style="border: solid 1px #cccccc "width="100%" border="0" cellpadding="00" cellspacing="00" >
<tr style="border-color: transparent">
<th bgcolor="#699BC5"><label style="color: white"><b>Item Name</b></label></th>
<th bgcolor="#699BC5"><label style="color: white"><b>Item Description</b></label></th>
<th bgcolor="#699BC5"><label style="color: white"><b>Item Qty</b></label></th>
<th bgcolor="#699BC5"><label style="color: white"><b>Item Rate</b></label></th>
<th bgcolor="#699BC5"><label style="color: white"><b>Total</b></label></th>
<th><INPUT type="button" value="Add Row" onclick="addRow('dataTable')" /></th>
<th><INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" /></th>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection connection1 = DriverManager.getConnection(connectionURL, "root", "freena");
PreparedStatement psmnt1 = connection1.prepareStatement("select * from mstpo ORDER BY POId DESC LIMIT 1 ");
ResultSet results1 = psmnt1.executeQuery();
while (results1.next()) {
String POid = results1.getString(1);
int id = Integer.parseInt(POid);
int poid = (id + 1);
%>
<td style="visibility: hidden"> <input type="text" name="Poid" value="<%=poid%>"/></td>
<%}
results1.close();
psmnt1.close();
%>
</tr>
<tr style="border-color: transparent">
<td>
<input type="text" name="ItemName" value=""/>
</td>
<td>
<input type="text" name="ItemDescription" value=""/>
</td>
<td>
<input type="text" name="txt1" value="" onkeyup="javascript:cal();"/>
</td>
<td>
<input type="text" name="txt2" value="" onkeyup="javascript:cal();"/>
</td>
<td>
<input type="text" name="txt3" value="" onmouseover="cal()"/>
</td>
</tr>
</table></td></tr>
<tr>
<td>
<table width="100%" border="1" bgcolor="#F0F9FF" style="border-color: #cccccc; border-style: solid" cellpadding="00" cellspacing="00">
<tr style="border: transparent;" >
<td></td>
<td>
<b>Basic Amount :</b> <INPUT type="text" id="total">
</td>
</tr>
<tr style="border: transparent;" >
<td align="right">
<b>VAT @ %</b> <INPUT type="text" value="" id="vat"name="vat" onkeyup=" javascript:cal1();">
</td>
<td>
<b>VAT Amount :</b> <INPUT type="text" name="vatamount" value="" id="vat1" onmouseover="javascript:cal1();">
</td>
</tr>
<tr style="border: transparent;" >
<td align="right">
<b>GST / CST %</b> <INPUT type="text" value="" name="tax" id="tax" onkeyup=" javascript:cal1();" >
</td>
<td>
<b>TAX Amount :</b> <INPUT type="text" name="taxamount" value="" id="tax1" onkeyup=" javascript:cal1();">
</td>
</tr>
<tr style="border: transparent;" >
<td></td>
<td>
<b>Grand Total :</b> <INPUT type="text" name="grandtotal" id="grandtotal" onmouseover="javascript:cal1();">
</td>
</tr>
</table>
</td>
</tr>
<tr >
<td colspan="5">
<input type="submit" value="Save" name="save" style=" color: teal" ></td>
<td</tr>
</form>
</table>
</td>
</tr>
</table>
<script>
function cal1(){
var a=0;
var b=0;
var c=0;
var v=0;
var t=0;
c=parseInt(document.getElementById("total").value);
a=parseInt(document.getElementById("vat").value);
b=parseInt(document.getElementById("tax").value);
v=parseFloat(document.getElementById("vat1").value);
t=parseFloat(document.getElementById("tax1").value);
document.getElementById("vat1").value=((a * c)/100);
document.getElementById("tax1").value=((b * c)/100);
document.getElementById("grandtotal").value=(v + t + c );
}
</script>
<script>
function cal(){
var i=0,j=0,sum=0;
arr = new Array();
arr1=new Array();
var input = document.getElementsByName('txt1');
for ( i = 0; i < input.length; i++ )
{
if ( input[i].type == 'text' )
{
arr.push(input[i] );
}
}
var input1 = document.getElementsByName('txt2');
for ( i = 0; i < input1.length; i++ )
{
if ( input1[i].type == 'text' ) {
arr1.push(input1[i]);
}
}
var t = document.getElementsByName('txt3');
for(i=0;i<arr.length;i++){
t[i].value=Number(arr[i].value)* Number(arr1[i].value);
}
var sum=0;
var lab=document.getElementById('total');
for(i=0;i<arr.length;i++)
{
sum=sum + Number(arr[i].value)* Number(arr1[i].value);
lab.value = sum;
}
}
</script>
</body>
</html>
newpo1.jsp::
<%--
Document : newpo1
Created on : Jun 21, 2010, 1:17:44 PM
Author : freena
--%>
<%@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.*,com.mysql.jdbc.Driver"%>
<%@ page import="java.io.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String text1[]=request.getParameterValues("ItemName");
String text2[]=request.getParameterValues("ItemDescription");
String text3[]=request.getParameterValues("ItemQty");
String text4[]=request.getParameterValues("ItemRate");
String text5[]=request.getParameterValues("total");
Connection con;
Statement st;
String PODate=request.getParameter("PoDate");
String POStatus=request.getParameter("POStatus");
String POAgent=request.getParameter("POAgent");
String POTerm=request.getParameter("POTerm");
String VendorId=request.getParameter("VendorId");
String VendorName=request.getParameter("VendorName");
String Vendoraddress=request.getParameter("VendorAddress");
String VendorCity=request.getParameter("VendorCity");
String VendorState=request.getParameter("VendorState");
String VendorCountry=request.getParameter("VendorCountry");
String VendorPostalcode=request.getParameter("VendorPostalcode");
String VendorEmail=request.getParameter("VendorEmail");
String VendorNumber=request.getParameter("VendorNumber");
String ContactPerson=request.getParameter("ContactPerson");
String vat=request.getParameter("vat");
String vatamount=request.getParameter("vatamount");
String tax=request.getParameter("tax");
String taxamount=request.getParameter("taxamount");
String grandtotal=request.getParameter("grandtotal");
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:
mysql://localhost:3306/material","root";, "freena");
st=con.createStatement();
String sql="insert into mstpo(PODate,POStatus,POAgent,POTerm,VendorId,VendorName,Vendoraddress,VendorCity,VendorState,VendorNumber,VendorCountry,Postalcode,VendorEmail,ContactPerson,VAT,VATAmount,TAX,TAXAmount,GrandTotal) values('"+PODate+"','"+POStatus+"','"+POAgent+"','"+POTerm+"','"+VendorId+"','"+VendorName+"','"+Vendoraddress+"','"+VendorCity+"','"+VendorState+"','"+VendorNumber+"','"+VendorCountry+"','"+VendorPostalcode+"','"+VendorEmail+"','"+ContactPerson+"','"+vat+"','"+vatamount+"','"+tax+"','"+taxamount+"','"+grandtotal+"')";
st.executeUpdate(sql);
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn=DriverManager.getConnection("jdbc:
mysql://localhost:3306/material","root";, "freena");
Statement st1 = conn.createStatement();
for(int i=0;i<text1.length;i++){
String POid=request.getParameter("Poid");
String itemname=text1[i];
String itemdescription=text2[i];
String itemqty=text3[i];
String itemrate=text4[i];
String total=text5[i];
st1.executeUpdate("insert into transactionpo(POId,ItemName,ItemDescription,ItemQty,ItemRate,total) values('"+POid+"','"+itemname+"','"+itemdescription+"','"+itemqty+"','"+itemrate+"','"+total+"')");
}
out.println("Record is inserted successfully");
%>
<jsp:forward page="listpo.jsp"></jsp:forward>
<%
st1.close();
st.close();
con.close();
%>
</body>
</html>