Set selected option on existing select tag with jstl

Viewed 30334

So I have a select for the grade on each subject. It's predefined and hence I don't have to store grades as a table in the database. I have a list of qualifications and I using jstl for each like this: <c:forEach items="${qualificationdetails}" var="qd">.

For each item I am producing a select like this.

<select class="grade" title="Grade Obtained">
   <option value="1">1</option>
   <option value="2">2</option>
   <option value="3">3</option>
   <option value="A">A</option>
   <option value="B">B</option>
   <option value="C">C</option>
   <option value="D">D</option>
   <option value="E">E</option>
</select>

Is it possible to set the selected option using my variable qd ? something like

<option value="${qd.grade}" selected="selecetd">${qd.grade}</option>

This will add a duplicate option to the select. I think it would a bit "clunky" to make an array with the grades and send it accross for generating the options. Any ideas ?

1 Answers
Related