如何保留我的下拉选择

时间:2016-01-11 06:33:35

标签: javascript java spring

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>

<%@ page session="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Employee Management System</title>
<link href="CSS/style.css" rel="stylesheet" type="text/css" />

<style>
.displayMessage{
    font-family:FontAwesome;
    font-style:normal;
    font-weight:400;
    display:inline-block;
    color: blue;
    background-color: #DFF2BF;
     margin:10px 22px;
     font-size:2em;
     content:'\f00c';
     vertical-align:middle;
      padding:12px;
}
.dropdown
    {
        margin-left: 730px;
        border-radius: 14px;
        font-size:13px; 

    }
.search{
    border-radius: 14px;
    background-color: #DFF2BF;
    font-family:Arial, Helvetica, sans-serif;
    font-style:italic;
    font-size:13px;         
    font-weight:bold;
    width: 250px;       
}

</style>



<script>
src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">
</script>
<script>

$(document).ready(function(){
    if('${ViewByName}'!='')
        {
            $('#ViewByName').val('${ViewByName}');
        }    
});
</script>
<script>
function confirmComplete() {
    var answer=confirm("Are you sure you want to delete the employee");

    if(answer) 
    {  
            alert("deleting the Employee");
            return true;

    }
    else
        {

                return false;
        }
        }
function confirmComplete1() {
    var answer=confirm("Are you sure you want to edit the employee details");

    if(answer) 
    {  

            return true;

    }
    else
        {

                return false;
        }
        }



</script> 
</head>

<body><center>
    <c:if test="${msg!= null}">
        <h1 class = "displayMessage">${msg}</h1>
        </c:if>

<h2>Employee Management Details </h2>
<form:form  action="view.html" modelAttribute="employee" method="POST">

<select id="ViewByName" class ="dropdown" name= "drop">
<!-- <option value="r">Select....</option> -->
  <option value="s">Starts With</option>
  <option value="c">Consist Of</option>
  <option value="e">Ends With</option>
</select>

            <div id="search-inner">
                <td>
                <form:input path="employeeName" type="text" name="search" maxlength="30" id="searchfield" title="searchfield" value="type the name of employee to search..." class = "search" onfocus="if (this.value=='type the name of employee to search...') this.value=''" 
                 onblur="if (this.value == '') this.value ='type the name of employee to search...'"/>

              <input type="submit" name="Search" value="Search"   title="Search" />

                </td>
            </div>
</form:form>

<table border="0" cellpadding="0" cellspacing="0">
 <br>
 </br>
  <tr>
    <td width="5%">Emp.ID</td>
    <td width="22%">Employee Name</td>
    <td width="6%">DOB</td>
    <td width="7%">Annual Income </td>
    <td width="9%">Blood group </td>
    <td width="11%">Qualification</td>
    <td width="7%">Sex</td>
    <td width="10%">Phone No.</td>
    <td width="9%">Email</td>
    <td width="7%">Edit</td>
    <td width="7%">Delete</td>
  </tr>

   <c:forEach items="${employeeList}" var="emp">  
   <tr>  
    <td>${emp.employeeId}</td>  
    <td>${emp.employeeName}</td>  
    <td>${emp.dateOfBirth}</td>
    <td>${emp.annualIncome}</td>
    <td>${emp.bloodGroup}</td>    
    <td>${emp.qualification}</td>  
    <td> ${emp.sex}</td>  
    <td>${emp.phoneNumber}</td>    
    <td>${emp.email}</td>    
    <td><a href="edit.html?ID=${emp.ID}" ><img  src="Pictures/edit.png" width="15px" height="15px"   onclick="return confirmComplete1()"/></a></td>
    <td><a href="delete.html?ID=${emp.ID}"><img src="Pictures/delete.png" width="15px" height="15px"  onclick="return confirmComplete()" /></a></td>

   </tr>  
  </c:forEach>

</table>
<div><a href="EmployeeRegister.html"><input name="" type="button" value="Back" /></a>

    </div>  
</center>
</body>
</html>

这是我的jsp页面,如果我刷新我的页面,我的下拉列表选择转到Starts with only always但我想要我刷新页面后我选择的下拉列表,即使刷新页面后我怎么能保留下拉列表选择。

1 个答案:

答案 0 :(得分:0)

clean the project and server and run the project and server again..

check this URL correctly
<script 
src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">
</script>
$(document).ready(function(){
    if('${name of class}'!='')//in my case name is drop 
        {
            $('#your id').val('${name of class}');//in my case id is ViewByName
        }    
});