Click here to Skip to main content
15,891,184 members
Home / Discussions / Java
   

Java

 
AnswerCross posted from C# forum Pin
Pete O'Hanlon12-Mar-13 22:05
mvePete O'Hanlon12-Mar-13 22:05 
Questionwhat is the difference between sendRedirect() and forward()? Pin
venky002811-Mar-13 19:38
venky002811-Mar-13 19:38 
AnswerRe: what is the difference between sendRedirect() and forward()? Pin
Sandeep Mewara11-Mar-13 20:44
mveSandeep Mewara11-Mar-13 20:44 
AnswerRe: what is the difference between sendRedirect() and forward()? Pin
vkscool24-Mar-13 21:01
vkscool24-Mar-13 21:01 
QuestionHow to use time picker in jsp? Pin
Phyo Thinzar Aung10-Mar-13 23:26
Phyo Thinzar Aung10-Mar-13 23:26 
AnswerRe: How to use time picker in jsp? Pin
Richard MacCutchan10-Mar-13 23:39
mveRichard MacCutchan10-Mar-13 23:39 
AnswerRe: How to use time picker in jsp? Pin
Shubhashish_Mandal14-Mar-13 0:26
professionalShubhashish_Mandal14-Mar-13 0:26 
QuestionHelp For Creating JSP invoice Pin
eMaM1519878-Mar-13 23:37
eMaM1519878-Mar-13 23:37 
Hi ...

I have tried to create Jsp Invoice but i have some problem i hope you can help me to do it ..

Blush | :O


This the javascript used to get price for the item
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="getprice.jsp";
       url +="?count="+encodeURI(str);
       xmlHttp.onreadystatechange = stateChange;
       xmlHttp.open("GET", url, true);
       xmlHttp.send(null);
   }

   function stateChange(){
       if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
           document.getElementById("price").innerHTML=xmlHttp.responseText
       }
   }






This is the Inovice Page at JSP


HTML
<%-- 
    Document   : invoicedev
    Created on : Mar 6, 2013, 3:27:07 PM
    Author     : eMaM
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>

<%
            response.setCharacterEncoding("UTF-8");
            request.setCharacterEncoding("UTF-8");
            String user = "root";
            String password = "0122308791";
            String host = "jdbc:mysql://localhost:3306/POSWITHACCOUNT";
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            Connection con = DriverManager.getConnection(host, user, password);
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT * FROM ITEMS");

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
    <HEAD>
        <TITLE> Add/Remove dynamic rows in HTML table </TITLE>
        <link rel="stylesheet" href="style.css">
        <link rel="license" href="http://www.opensource.org/licenses/mit-license/">
        <script src="script.js"></script>
        <script src="jquery.js" type="text/javascript"></script>
        <SCRIPT language="javascript">

             


            function getrow() {
                if (!document.getElementsByTagName || !document.createTextNode) return;
                var rows = document.getElementById('dataTable').getElementsByTagName('tr');
                var rowtyp=0;
                for (i = 0; i < rows.length; i++) {
                    rows[i].onclick = function() {
                        rowtyp= this.rowIndex + 1;
                        
                    }
                }

                
               
            }



            


                        

            function addRow(tableID) {

                var table = document.getElementById(tableID);

                var rowCount = table.rows.length;
                var row = table.insertRow(rowCount);

                var colCount = table.rows[0].cells.length;

                for(var i=0; i<colCount; i++) {

                    var newcell = row.insertCell(i);

                    newcell.innerHTML = table.rows[1].cells[i].innerHTML;
                    // alert(newcell.childNodes);
                   
                    
                }
                 
            }

            function deleteRow(tableID) {
                try {
                    var table = document.getElementById(tableID);
                    var rowCount = table.rows.length;

                    for(var i=0; i<rowCount; i++) {
                        var row = table.rows[i];
                        var chkbox = row.cells[0].childNodes[0];
                        if(null != chkbox && true == chkbox.checked) {
                            if(rowCount <= 1) {
                                alert("Cannot delete all the rows.");
                                break;
                            }
                            table.deleteRow(i);
                            rowCount--;
                            i--;
                        }


                    }
                }catch(e) {
                    alert(e);
                }
            }

        </SCRIPT>
    </HEAD>
    <BODY>
        <h1>Recipient</h1>
        <address contenteditable>
            <p>Some Company<br>c/o Some Guy</p>
        </address>
        <form>
        <table class="meta">
            <tr>
                <th><span contenteditable>Invoice #</span></th>
                <td><span contenteditable>101138</span></td>
            </tr>
            <tr>
                <th><span contenteditable>Date</span></th>
                <td><span contenteditable>January 1, 2012</span></td>
            </tr>
            <tr>
                <th><span contenteditable>Amount Due</span></th>
                <td><span id="prefix" contenteditable>$</span><INPUT type="text" name="eStop" id="eStop" /></td>
            </tr>
        </table>




        <TABLE id="dataTable" width="350px" border="1" class="inventory">
            <thead>
                <tr >
                    <th width="30px"><span contenteditable>No</span></th>
                    <th><span contenteditable>Items</span></th>
                    <th><span contenteditable>Description</span></th>
                    <th><span contenteditable>Quantity</span></th>
                    <th><span contenteditable>Price</span></th>
                    <th><span contenteditable>Tax</span></th>
                    <th><span contenteditable>Total</span></th>
                </tr>
            </thead>
            <TR >
                <TD width="30px"><INPUT type="checkbox" name="chk" /></TD>

                <TD>
                    <SELECT name="items" onclick="showState(this.value)" onkeydown="showState(this.value)" onkeyup="showState(this.value);getrow()" class="uname">
                        <OPTION value="in">Select Items to Sale . .</OPTION>
                        <% while (rs.next()) {%>
                        <option value="<%=rs.getInt("idITEMS")%>"><%=rs.getString("ITEMNAME")%></option>
                        <%}%>

                    </SELECT>
                </TD>
                <TD><INPUT type="text" name="desc"/></TD>
                <TD><INPUT type="text" name="quantity"/></TD>
                <TD><div id="price"><INPUT type="text" name="price" value="0.0" /></div></TD>
                <TD><INPUT type="text" name="tax"  id="val" value="0.0"/></TD>
                <TD><INPUT type="text" name="total" value="0.0"/></TD>
            </TR>

        </TABLE>
        
        <br><br><br>
        <INPUT type="button" value="+" onclick="addRow('dataTable')" class="add"/>

        <INPUT type="button" value="deket" onclick="deleteRow('dataTable')" />

        </form>

    </BODY>
</HTML>




THIS IS THE getprice.jsp

page to get price
ASP.NET
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>

<%
            response.setCharacterEncoding("UTF-8");
            request.setCharacterEncoding("UTF-8");
            String user = "root";
            String password = "0122308791";
            String host = "jdbc:mysql://localhost:3306/POSWITHACCOUNT";
            String buffer = "";
            try {
                Class.forName("com.mysql.jdbc.Driver").newInstance();
                Connection con = DriverManager.getConnection(host, user, password);
                Statement stmt = con.createStatement();
                ResultSet rs = stmt.executeQuery("SELECT SALEPRICE,BARCODE FROM ITEMS WHERE idITEMS='"+request.getParameter("count")+"'");
                double price=0.0;
                while (rs.next()) {
                    price=rs.getDouble("SALEPRICE");
                }
                out.println(price);
                buffer = buffer + "<INPUT type='text' name='price' value='"+price+"'/>";
                response.getWriter().println(buffer);
            } catch (Exception e) {
                System.out.println(e);
            }
%>



The problem now

when i add new row and select item the item price affect at the price cell at the first row only ??


Now how can i went add new row and select new item the price of item show at the it`s row ?
AnswerRe: Help For Creating JSP invoice Pin
Richard MacCutchan10-Mar-13 23:37
mveRichard MacCutchan10-Mar-13 23:37 
QuestionAudio Sample Playback Pin
dusty_dex7-Mar-13 15:46
dusty_dex7-Mar-13 15:46 
AnswerRe: Audio Sample Playback Pin
Richard MacCutchan7-Mar-13 21:58
mveRichard MacCutchan7-Mar-13 21:58 
Questionjtds connection problem.... SQL Server 2012 Express Pin
MacRaider47-Mar-13 3:22
MacRaider47-Mar-13 3:22 
AnswerRe: jtds connection problem.... SQL Server 2012 Express Pin
MacRaider47-Mar-13 7:03
MacRaider47-Mar-13 7:03 
AnswerHibernate Data base connection lost Pin
kvsravindrareddy12-Mar-13 21:04
kvsravindrareddy12-Mar-13 21:04 
SuggestionRe: jtds connection problem.... SQL Server 2012 Express Pin
Prasad Khandekar2-May-13 20:12
professionalPrasad Khandekar2-May-13 20:12 
QuestionRetails invoice Pin
eMaM1519877-Mar-13 0:39
eMaM1519877-Mar-13 0:39 
AnswerRe: Retails invoice Pin
Sandeep Mewara7-Mar-13 1:24
mveSandeep Mewara7-Mar-13 1:24 
Questionjava help Pin
okedi5-Mar-13 22:15
okedi5-Mar-13 22:15 
AnswerRe: java help Pin
Richard MacCutchan5-Mar-13 22:22
mveRichard MacCutchan5-Mar-13 22:22 
Questiondemende help Pin
لحن الأماني5-Mar-13 9:50
لحن الأماني5-Mar-13 9:50 
AnswerRe: demende help Pin
Master.Man19805-Mar-13 10:21
Master.Man19805-Mar-13 10:21 
Questiondemende help Pin
لحن الأماني5-Mar-13 9:50
لحن الأماني5-Mar-13 9:50 
AnswerRe: demende help Pin
dusty_dex6-Mar-13 4:52
dusty_dex6-Mar-13 4:52 
Questiondemende d'aide Pin
لحن الأماني5-Mar-13 8:17
لحن الأماني5-Mar-13 8:17 
AnswerRe: demende d'aide Pin
Jibesh5-Mar-13 8:47
professionalJibesh5-Mar-13 8:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.