html5 - How to keep the multiple selected value in dropdown using jstl tags? -


        //this jsp code.........         <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>           <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>           <html>           <head>           <title>drop down</title>          <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>           <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>           <script type="text/javascript">         $(document).ready(function() {             $("#delete").click(function(){                 var d = [];                 $.each($("#delete option:selected"), function(){                                d.push($(this).val());                 });                 var s=(d.join(", "));                 console.log(s);                $("#delete_empid").val(s);                console.log($("#delete_empid").val());              });         });         </script>         </head>           <body>               <div align="center">             <form:form method="post" action="${pagecontext.request.contextpath}/deletemultiple" modelattribute="employee">               <table>               <tr>                 <td>first name :</td>                 <td><form:input path="firstname" /></td>                </tr>                <tr>                 <td>last name :</td>                 <td><form:input path="lastname" /></td>                </tr>               <tr>                 <td>emp_id :</td>                 <td><form:input path="emp_id" /></td>                </tr>               <tr>               <td>email_id :</td>               <td><form:input path="email_id"/></td>              </tr>              <tr>               <td>phone_no :</td>               <td><form:input path="phone_no"/></td>              </tr>              <tr>               <td>city :</td>               <td><form:input path="city"/></td>              </tr>              <tr>                 <td> </td>                 <td><input type="submit" value="search" /></td>                 </tr>               </table>             <input type= "hidden" id="delete_empid" name="delete_empid"   />               </form:form>         </div>           <div  align="center">             <h2 style="color:blue">selectbox:</h2>            <form:form method="post" action="${pagecontext.request.contextpath}/deletemultipleempdetails">               <select id="delete"  multiple name="employees">              <c:foreach items="${emplist}" var="employee">               <option value= "${employee.emp_id}" >${employee.firstname}</option>              ${msg}             </c:foreach>             </select>               <input type="submit" name="delete" value="delete">             </form:form>           </div>              <div>                  <h4 style="color:red">${message}</h4>               </div>          </body>           </html>   

how keep value selected using jstl tags, without using javascript?

to keep multiple selected value, need add selected attribute respective <option> tag.

i thinking that, want add selected attribute based on condition, using <c:choose> tag.

try following code:

<select id="delete"  multiple name="employees">     <c:foreach items="${emplist}" var="employee">       <c:choose>        <c:when test="${some condition satisfies requirement }">            <option value= "${employee.emp_id}" selected="selected"> ${employee.firstname} </option>        </c:when>        <c:otherwise>            <option value= "${employee.emp_id}" >${employee.firstname}</option>        </c:otherwise>    </c:choose>   </c:foreach> </select>  

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -