i recovered list of establishment through servlet, list travel dropdown element displayed dynamically.
so recovered value x of field same servlet. value 1 of elements of list.
i want value appears default in dropdown value x recovered. here's code:
<td> <select id="liste_etab" name="liste_deroulante_etablissement" > <c:foreach var="e" items="${requestscope['listeetablissement']}"> <option value="${e.id}">${e.libelle_etab}</option> </c:foreach> </select> </td> <!-- value recovered is: ${requestscope['champpasse']} -->
to make option default in select in html
, need add attribute selected
option. rewrite code as
<c:foreach var="e" items="${requestscope['listeetablissement']}"> <c:if test="${e.id == x}"> <option value="${e.id}" selected>${e.libelle_etab}</option> </c:if> <c:if test="${eid != x}"> <option value="${e.id}">${e.libelle_etab}</option> </c:if> </c:foreach> </select>
Comments
Post a Comment