Hi guys.
I have this code disturbing me and I don't know how to sort it out, can somebody help me out?I want to load data from mysql database to these text boxes on selection of Input_id and every time I change the Input_id, the data should also change.

Code
<body>

        <table width="780" align=center cellspacing=0 border="4" cellpadding=0>


        <%@ page import="java.sql.*"%>
        <jsp:include page="fr_transaction.jsp" /><br>
        <%
            if (session.getValue("login") != null) {
                //response.sendRedirect("RMShome.htm?invalidsession");
            }
            Connection con = null;
            PreparedStatement sst = null;
            Statement st = null;
            ResultSet rs = null;
            ResultSet rs2 = null;
            ResultSet rs3 = null;

        %>
        <script type="text/javascript">

            function selectData(){
               iname= 
            }

        </script>
        <tr><td>
                <table width="1000" height="300"align=center cellspacing=0 border="0" cellpadding=0>
                    <tr><td>
                            <fieldset id="fieldhead">
                                <legend>Farm Input Purchase</legend><BR>
                                <table align=center cellspacing=1 cellpadding=3><form method=post onload="">
                                        <center>
                                            <tr><td><b>Input Id</b></td><td></td>

                                                <td><b>Input Name</b></td><td><b>Description</b></td><td><b>Weight</b></td><td></td><td><b>Price</b></td>
                                                <td><b>Quantity</b></td><td><b>Total Cost</b></td></tr>
                                            <tr>

                                                <td colspan=2>
                                                    <select inputid="select" onselect="selectData();">

                                                        <% try {
                                                                Class.forName("com.mysql.jdbc.Driver");
                                                                con = DriverManager.getConnection("jdbc:mysql://localhost:3306/employ", "root", "");
                                                                st = con.createStatement();
                                                                String cmd2 = "Select input_id,input_name from item";
                                                                rs2 = st.executeQuery(cmd2);

                                                                while (rs2.next()) {
                                                                    String input_id = rs2.getString("input_id");
                                                                    String input_name = rs2.getString("input_name");

                                                                    out.println("<option input_id='" + input_id + "' input_name='" + input_name + "' >" + input_id + "</option>");
                                                                }

                                                            } catch (Exception e) {
                                                                out.println("<option val='null'>" + e.getMessage().toString() + "</option>");
                                                            }
                                                        %>
                                                    </select>
                                                <td><input type="text" name="iname"></td>
                                                <td><input type="text" name="description"></td>
                                                <td colspan=2>
                                                    <select weight="select">Select

                                                        <% try {
                                                                Class.forName("com.mysql.jdbc.Driver");
                                                                con = DriverManager.getConnection("jdbc:mysql://localhost:3306/employ", "root", "");
                                                                st = con.createStatement();
                                                                String cmd2 = "Select weight,input_name from item";
                                                                rs2 = st.executeQuery(cmd2);

                                                                while (rs2.next()) {
                                                                    String weight = rs2.getString("weight");
                                                                    String input_name = rs2.getString("input_name");

                                                                    out.println("<option weight='" + weight + "' input_name='" + input_name + "' >" + weight + "</option>");
                                                                }

                                                            } catch (Exception e) {
                                                                out.println("<option val='null'>" + e.getMessage().toString() + "</option>");
                                                            }
                                                        %>
                                                    </select>

                                                <td><input type="number" name="price" min="1" readonly="" ></td>
                                                <td><input type="number" name="qnty" min="0" ></td>
                                                <td><input type="number" name="qnty" min="0" readonly="" ></td>
                                            </tr>

                                            <tr><td></td><td></td><td></td><td></td><td></td><td colspan=2 align=center><button type=submit accesskey="A"><u>P</u>rocess</button>
                                                      <button type=reset accesskey="R"><u>R</u>efresh</button></td></tr>
                                        </center>
                                </table><BR>
                            </fieldset>
                        </td></tr></table>
            </td></tr>
    </table>
</body>

</html>

My table contains this

input_name  varchar(20)

description text
weight varchar(10)
price float
quantity float
Date datetime
Total float

Snapshot of the window is attached

my advice: learn to use servlets before you try and add a database in the mix.
your code 'll become unreadable otherwise.

also: with what part are you having trouble? is there an error? are you just stuck somewhere on the logic? ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.