I'm new to JSP i have tried to find a solution for my problem but unfortunately i couldn't. So what i m trying to do is to have 2 dropdowns and when i select a value from the first list second drop down must be filtered. And here's what i did so far : Servlet passes below objects to jsp :
getServletContext().setAttribute("foodDetails", fds.findAll());
request.getRequestDispatcher(url).forward(request, response);
In jsp code i create two dropdowns and populate the lists using below code :
<tr>
<td>Detay Tipi 1</td>
<td>
<select name="tip" id="tip" onchange="">
<option value="porsiyon">porsiyon</option>
<option value="extra">extra</option>
</select>
</td>
<td>
<select name="tip2" id="tip2" onchange="">
<option value"Lütfen Tip Seçiniz">Lütfen Tip Seçiniz</option>
</select>
</td>
</tr>
So when user selects "porsiyon" from first dropdown, second list will be populated with values from ${foodDetails}. To achieve this i overwrote first drop down's onchange method using below code :
<script type="text/javascript">
$(document).ready(function(){
$("#tip").change(function(){
tip2.length = 1;
var x=$(this).val();
<c:forEach var="fd" items="${foodDetails}">
<c:if test="${fd.detailcategory == x}">
tip2.options[tip2.options.length] = new Option("${fd.name}","${fd.name}");
</c:if>
</c:forEach>
});
});
</script>
this unfortunately doesn't work, when i switch
var x=$(this).val();
with static value like :
<c:set var="x" scope="session" value='ekstra'/>
it Works like charm where c is defined as :
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>.
I maybe doing a very obvious mistake but i can't figure out what. This is my first jsp page so go easy on me :) PS : i don't think classes are needed to answer this but fooddetails has a list of fooddetail where fooddetail.detailcategory can be either "porsiyon" or "ekstra".
thanks,