0

I am want set default value= ${theObject2.countryId}

<select id="locationCountry" style="padding-left: 2em" >
<option value="">Country</option>
<c:forEach  items="${countrieDetail}" var="theObject" varStatus="theCount">
<option value="${theObject.countryId}" >${theObject.countryName}</option>
</c:forEach>
</select>
rachana
  • 3,344
  • 7
  • 30
  • 49
user3759807
  • 3
  • 1
  • 2

1 Answers1

0

You can use HTML selected Attribute. Simply compare the Id and set it selected if matched.

Sample code:

<select id="locationCountry" style="padding-left: 2em">
    <option value="">Country</option>
    <c:forEach items="${countrieDetail}" var="theObject">
        <option value="${theObject.countryId}" <c:if test="${theObject.countryId == theObject2.countryId }">selected</c:if>>
              ${theObject.countryName}
        </option>
    </c:forEach>
</select>
Braj
  • 46,415
  • 5
  • 60
  • 76
  • Look at this post as well [Keeping radio buttons selected with jsp](http://stackoverflow.com/questions/24328294/keeping-radio-buttons-selected-with-jsp) where same logic is used to make it more clear. – Braj Jun 20 '14 at 16:44