如何存储输入值并将其用于比较而不提交表格

时间:2015-04-24 17:40:41

标签: jquery jsp textbox form-submit

我想接受' NO of Days'并将其作为限制条件,用于检索预定义的推荐人员'和制裁官员'在同一个JSP页面上的文本框中。

<%@ page import="java.sql.*"%>
<%@ page import="java.util.*,java.io.*" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
 <script src="//code.jquery.com/jquery-1.10.2.js"></script>
 <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
 <link rel="stylesheet" href="/resources/demos/style.css">
 <script>
 $(function() {
 $( "#datepicker" ).datepicker();
 });
 </script>

 <title>Leave Apply Form</title>

<% 
String ic_n =(String)session.getAttribute("ic_no");

try {
 Class.forName("oracle.jdbc.driver.OracleDriver");
 Connection con= DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","sys");

 %>
 </head>


 <body bgcolor="#FFCC99">
 <a href="Logout" style="float:right">Logout</a>
 <p> Today's date: <%= (new java.util.Date()).toLocaleString()%>  </p>
 <center>
 <h1><b>Solid State Physics Laboratory</b></h1>
 <h3><u>Leave Application Form</u></h3>
  </center>
 <center>


  <%    String Recommended_Officer=" ";
  String Sanction_Officer=" ";
  Statement s=con.createStatement();
  String query = "select ic_no,firstname,lastname,dept,designation from empinfo where ic_no='"+ic_n+"'";
   Statement st = con.createStatement();
  ResultSet rs = st.executeQuery(query);
  if(rs.next())
    {
    %>

   <form>
   <table width="537" height="187">
    <tr>

     <td>IC_NO </td> <td><input type="text" size="10" name="ic_no" value="<%=rs.getString("ic_no")%>"></td>
     </tr>
     <tr>
     <td>FirstName</td><td> <input type="text" size="25" name="firstname" id="firstname" value="<%=rs.getString("firstname")%>"></td>
      <td>LastName </td><td><input type="text" size="25" name="lastname" id="lastname" value="<%=rs.getString("lastname")%>"></td>
   </tr>
   <tr>
   <td>Department</td> <td><input type="text" size="25" name="dept" id="dept" value="<%=rs.getString("dept")%>"></td>
    <td>Designation </td> <td><input type="text" size="20" name="designation" id="designation" value="<%=rs.getString("designation")%>"></td>
    </tr>
    <tr>
    <td>Date of Applying</td><td><input type="text" id="datepicker"></td>
    </tr>

     <tr>
     <td>Type Of Leave</td>
        <td>
      <select>
       <option></option>
        <option>Casual Leave</option>
         <option>Maternity Leave</option>
          <option>Paternity Laeve</option>
           </select>
         </td>
       <td>No of Days</td><td><input type="text"  size="40" name="No of days" id="No_of_days" value=""></td>
        </tr>
       <tr>
        <%  
    String Department= request.getParameter("dept"); 

      int No_of_days= Integer.parseInt(request.getParameter("No of days")); 
      if (Department.equals(null))
    {  Recommended_Officer="Mr. H.S KALSi";
     Sanction_Officer="Mr. H.S KALSi";

       }
        else if (Department.equals("itg"))

        {   if (No_of_days > 0 &&  No_of_days <= 5)
            {
               Recommended_Officer="Mr. KS";
               Sanction_Officer="Mr. ks";
             }
         else if(No_of_days >5 &&  No_of_days <=10)
           {         Recommended_Officer="Mr. KS";
                    Sanction_Officer="Mr. JSBS";    }

             else if(No_of_days >10 &&  No_of_days <=30)
          {      Recommended_Officer="Mr.JSBS";
                  Sanction_Officer="Mr. HS KALSi";  }

                else if (No_of_days > 30)

              { Sanction_Officer="Mr. H.S KALSi"; } 

                       }

                else    
            {
            Recommended_Officer="Mr. H.S KALSi";
            Sanction_Officer="Mr x ";
              } 

            %>
               <tr>
        <td>Recommended Officer</td><td> <input type="text" size="40" name="Recommended Officer" id="Recommended_Officer" value="<%=Recommended_Officer%>"></td>
        </tr>
        <tr>
     <td>Sanction Officer</td><td> <input type="text" size="40" name="Sanction Officer" id="Sanction_Officer" value="<%=Sanction_Officer%>">  </td>
    </tr>

    <tr>
     <td>Start Date</td><td><input type="text" id="datepicker"></td>
     <td>End Date</td><td><input type="text" id="datepicker"></td>
    </tr>
    </table>
        <table>
         <tr>
            <td>Reason for Leave</td><td><input type="text" Size="60"></td>
           </tr>


            <tr>
            <td>Availing LTC</td>
        <td><select><option>Yes</option>
            <option>No</option>
             </select>
            </td>
            </table>
        <br><br><input type="submit" value="Submit"> 
         <input type="reset">





              <%
              }
                     }
        catch(Exception e){
        out.print("exception");
         }
          %>
        </form>
    <% %></center>
       </body>
      </html>

1 个答案:

答案 0 :(得分:0)

function assignOfficer() {
  var recommendedOfficer;
  var sanctionOfficer;
  var numOfDays = $('#No_of_days').val();
  //Your various condition to assign officer in 'recommendedOfficer' and 'sanctionOfficer'
  $('#Recommended_Officer').val(recommendedOfficer);
  $('#Sanction_Officer').val(sanctionOfficer);
}