jackjuma12 0 Newbie Poster

Hi guys

Can anybody tell me what is wrong with this code? When I select the contractor number (with only one script code)it loads the details, but when I add the second function to load the farmer details, non now works!!!!! What am I doing wrong

code

<%@ page import="java.sql.*" %> 
<html>
    <head>
        <style>
            A:hover {text-decoration: none;

                     border: 0px;
                     font-size:14pt;
                     color: #2d2b2b; }
            </style>

            <link rel="stylesheet" type="text/css" href="datepicker.css"/>


            <script type="text/javascript">
                function showEmp(emp_value)
                {
                    if (document.getElementById("contractor_no").value != "-1")
                    {
                        xmlHttp = GetXmlHttpObject()
                        if (xmlHttp == null)
                        {
                            alert("Browser does not support HTTP Request")
                            return
                        }
                        var url = "getcontractor.jsp"
                        url = url + "?contractor_no=" + emp_value

                        xmlHttp.onreadystatechange = stateChanged
                        xmlHttp.open("GET", url, true)
                        xmlHttp.send(null)

                    }
                    else
                    {
                        alert("Please Select Contractor Number");
                    }
                }

                function stateChanged()
                {
                    document.getElementById("contractor_name").value = "";
                    document.getElementById("contractor_no").value = "";

                    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
                    {

                        var showdata = xmlHttp.responseText;
                        var strar = showdata.split(":");

                        if (strar.length == 1)
                        {
                            document.getElementById("contractor_no").focus();
                            alert("Please Select Contractor No");
                            document.getElementById("contractor_name").value = " ";
                            document.getElementById("contractor_no").value = " ";


                        }
                        else if (strar.length > 1)
                        {
                            var strname = strar[1];
                            document.getElementById("contractor_no").value = strar[1];
                            document.getElementById("contractor_name").value = strar[2];

                        }
                    }
                }

                function GetXmlHttpObject()
                {
                    var xmlHttp = null;
                    try
                    {
                        // Firefox, Opera 8.0+, Safari
                        xmlHttp = new XMLHttpRequest();
                    }
                    catch (e)
                    {
                        //Internet Explorer
                        try
                        {
                            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
                        }
                        catch (e)
                        {
                            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                    }
                    return xmlHttp;
                }

                 function showEmp1(emp_value)
                {
                    if (document.getElementById("farmerno").value != "-1")
                    {
                        xmlHttp = GetXmlHttpObject()
                        if (xmlHttp == null)
                        {
                            alert("Browser does not support HTTP Request")
                            return
                        }
                        var url = "getfarmer.jsp"
                        url = url + "?farmerno=" + emp_value

                        xmlHttp.onreadystatechange = stateChanged
                        xmlHttp.open("GET", url, true)
                        xmlHttp.send(null)

                    }
                    else
                    {
                        alert("Please Select Farmer Number");
                    }
                }

                function stateChanged()
                {
                    document.getElementById("fname").value = "";
                    document.getElementById("farmerno").value = "";

                    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
                    {

                        var showdata = xmlHttp.responseText;
                        var strar = showdata.split(":");

                        if (strar.length == 1)
                        {
                            document.getElementById("farmerno").focus();
                            alert("Please Select Farmer Number");
                            document.getElementById("fname").value = " ";
                            document.getElementById("farmerno").value = " ";


                        }
                        else if (strar.length > 1)
                        {
                            var strname = strar[1];
                            document.getElementById("farmerno").value = strar[1];
                            document.getElementById("fname").value = strar[2];

                        }
                    }
                }

                function GetXmlHttpObject()
                {
                    var xmlHttp = null;
                    try
                    {
                        // Firefox, Opera 8.0+, Safari
                        xmlHttp = new XMLHttpRequest();
                    }
                    catch (e)
                    {
                        //Internet Explorer
                        try
                        {
                            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
                        }
                        catch (e)
                        {
                            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                    }
                    return xmlHttp;
                }
            </script>

        </head>
        <body>
            <%
                Connection conn = null;
                String url = "jdbc:mysql://localhost:3306/";
                String dbName = "employ";
                String driver = "com.mysql.jdbc.Driver";
                String userName = "root";
                String password = "";
                int sumcount = 0;
                Statement st;
            %>
            <form name="contractor" method="post" action="harvestingjobassign">
                <br><br>
                <table border="2" width="auto" align="center" bgcolor="#CDFFFF">
                    <div id="mydiv"></div>
                <tr><td><b>Select Contractor No</b></td><td> 
                        <select name="contractor_no" onchange="showEmp(this.value);">
                            <option value="-1">Select</option> 
                            <%
                                conn = null;
                                url = "jdbc:mysql://localhost:3306/";
                                dbName = "employ";
                                driver = "com.mysql.jdbc.Driver";
                                userName = "root";
                                password = "";

                                sumcount = 0;

                                try {
                                    Class.forName(driver).newInstance();

                                    conn = DriverManager.getConnection(url + dbName, userName, password);
                                    String query = "select * from contractors";

                                    st = conn.createStatement();
                                    ResultSet rs = st.executeQuery(query);
                            %>

                            <%
                                while (rs.next()) {
                            %>

                            <option value="<%=rs.getString(1)%>"><%=rs.getString(1)%></option> 

                            <%
                                }
                            %>

                            <%
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }

                            %>

                        </select>
                    </td></tr>


                <tr><td><b>Contractor Name:</b></td><td><input  type="text" name="contractor_name" id="contractor_no" value=""></td>
                    <td><b>Type:</b></td><td><input  type="text" name="contractor_name" id="contractor_name" value=""></td>

                <tr><td><b>Select Farmer No</b></td><td> 
                        <select name="farmerno" onchange="showEmp1(value);">
                            <option value="-1">Select</option> 

                            <%   conn = null;
                                url = "jdbc:mysql://localhost:3306/";
                                dbName = "employ";
                                driver = "com.mysql.jdbc.Driver";
                                userName = "root";
                                password = "";

                                sumcount = 0;

                                try {
                                    Class.forName(driver).newInstance();

                                    conn = DriverManager.getConnection(url + dbName, userName, password);
                                    String query = "select * from customer";

                                    st = conn.createStatement();
                                    ResultSet rs = st.executeQuery(query);
                            %>

                            <%
                                while (rs.next()) {
                            %>

                            <option value="<%=rs.getString(1)%>"><%=rs.getString(1)%></option> 

                            <%
                                }
                            %>

                            <%
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }

                            %>

                        </select>
                    </td></tr>


                <tr><td><b>Farmer Name:</b></td><td><input  type="text" name="fname" id="fname" value=""></td>
                    <td><b>Field No.:</b></td><td><input  type="text" name="deed" id="deed" value=""></td>
                    <td><b>County:</b></td><td><input  type="text" name="county" id="county" value=""></td>
                    <td><b>Zone:</b></td><td><input  type="text" name="zone" id="zone" value=""></td>
                    <td><b>Area:</b></td><td><input  type="text" name="area" id="area" value=""></td>
                <td><b>Acre:</b></td><td><input  type="text" name="acre" id="acre" value=""></td></tr>


                 <tr><br><td colspan=2 align=center><button type=submit value="product" accesskey="A"><u>A</u>ssign</button>
                    &nbsp;&nbsp;<button type=reset accesskey="R"><u>R</u>efresh</button></td></tr>
            </table>

        </form>

    </body>
</html>