I will try to simplify the code.
Basically in my jsp file when the document has been loaded, the select values are filled in automatically.
For example:
<div class="col-sm">
<label style="font-size: 20px;"><fmt:message key="cap.workplace"/>: </label>
<select id="SelectWorkshop" class="chosen-select selectFilter">
<option selected="selected" value="0"><fmt:message key="cap.todos"/></option>
<c:forEach items="${workshopList}" var="workshopList">
<option value="${workshopList.idLocation}"><c:out value="${workshopList.location}" /></option>
</c:forEach>
</select>
</div>
But depending on what the user does, I will need to modify the original select value for another one, let's say I call a Javascript function that does:
$("#SelectWorkshop").empty();
var tempvalue = "<option>This is a demo for Stackoverflow</option>";
$( "#SelectWorkshop" ).html(tempvalue);
After this code is executed, the previous content of the select is gone and I can see the new content, which is what I want.
But I would like to create a button, called "Reset filters" (for example) to get the 'original' values of the select.
I tried creating a button called ResetFilters and then do this (which is basically injecting the previous content):
$("#ResetFilters").click(function(){
$("#SelectWorkshop").replaceWith(<option selected="selected" value="0"><fmt:message key="cap.todos"/></option>
<c:forEach items="${workshopList}" var="workshopList">
<option value="${workshopList.idLocation}"><c:out value="${workshopList.location}" /></option>
</c:forEach>);
});
But it's not working, basically the syntax is not correct, how can I inject html & jstl altogether? I don't know if it's the most correct way to do it.
Does anyone know how to do it in the most efficient way?