0

I have a spring boot application with frontend using thymeleaf and bootstrap. I have dropdown list on a questionnaire, which is populated with a list of options. But when I create a new questionnaire or I always get first option as selected of the list instead of "Select Answer" which should be default if no option is selected.

enter image description here

But I want by default "Select Answer to be selected"

enter image description here

The html for this dropdown section is as follows:

    <td class="col-4">
                                    <select th:field="*{questionnaire.questions[__${iStat.index}__].possibleAnswers[0].id}" class="form-control">
<!--                                        <option th:value="0" th:selected="true">Select Answer</option>-->
                                        <option value="0" selected="selected" >Select Answer</option>
                                        <option th:each="possibleAnswer : ${question.getPossibleAnswers()}"
                                                th:value="${possibleAnswer.id}"
                                                th:text="${possibleAnswer.text}"></option>
                                    </select>
                                </td>

Could anyone please suggest how can make this dropdown select "Select Answer" as default.

  • 1
    https://stackoverflow.com/questions/24203220/thselected-a-number-in-a-select-option-with-thymeleaf-doesnt-work – Ralph Oct 27 '22 at 20:19

0 Answers0