I am populating the combo box using data from db. Also i am checking the default n setting it as selected.
<select name="managerID">
<option value="0">None</option>
<c:forEach items="${employees}" var="employee">
<option value="${employee.id}" <c:if test="${edit.managerId == employee.id}">selected="selected"</c:if>>${employee.firstName} ${employee.lastName}, ${employee.email}</option>
</c:forEach>
</select>
the problem is that when i submit i always get the default value and not the user selected one.
hes sorry to have troubled you I found what was wrong with the code.
I rechecked the code there was a hidden field with name managerID and it contained the default value.
Related
I am working in an application where i have a list box with some values there ,i am selecting a value from there and then i am submitting it.The value is inserted into the database properly.Now what i want ,i want when the user again login to the from he should be able to see that selected values in the listbox.I am able to pick the value from the database when the user is loggin into the system .But i can not manage to show it selected ,Here is my code
<tr>
<th>What would be the single biggest motivator in a potential new opportunity?</th>
<td>
<select id="motivator" name="motivator" multiple="multiple">
<% while(rs8.next()){
motivatorString = rs8.getString("motivators");
%>
<option value ="<%=motivatorString %>" ><%=motivatorString %> </option>
<%} %>
</select>
</td>
</tr>
How can i achieve that ??
Use attribute selected="selected" for option like:
<option value ="<%=motivatorString %>" selected="selected_only_if__motivatorString_value_equals_value_from_db"><%=motivatorString %> </option>
selected_only_if__motivatorString_value_equals_value_from_db is just a placeholder to tell u that replace it with "selected" when the string matches the value in DB
I am working in a application where i have a select box where i got values from the database.Now i have to select one value that will go to the database,it is going but when i am logging out from the page the the value is not there how to solve this ?? i am getting the selected value back in the jsp page when i am logging into the jsp page. As i am posting my code
motivator = existingProfile.get(i).getMotivator();
<th>What would be the single biggest motivator in a potential new opportunity?</th>
<td>
<select id="motivator" name="motivator" multiple="multiple">
<% while(rs8.next()){
motivatorString = rs8.getString("motivators");
System.out.println("motivatorString :"+motivator);
%>
<option value ="<%=motivatorString %>" ><%=motivatorString %> </option>
<%} %>
</select>
</td>
this motivator is holding the selected value i want it selected along with the other values in the select box
i have a question when i try to capture the value of dropdown list from jsp file to servlet.
<select name="extraroom">
<c:if test="${booking.roomType ne 'single'}">
<c:forEach var="i" begin="0" end="${booking.count}">
<option value="<c:out value="${i}"/>"><c:out value="${i}"/></option>
</c:forEach>
</c:if>
</select>
i use Integer.parseInt(request.getParameter("extraroom"))
i have many drop down lists according to different roomType.
but the result in java servlet always get the value of the first dropdown lists...
what should i change in servlet?
Thank you.
For a select to be retrieved by a server the select has to
be inside a form and
have a unique name identifier inside (it; best the identifier is unqiue across the entire DOM tree)
In my project. I want to populate the drop down list on a jsp from a database.
<select id="names" name="names"> <c:forEach items="${names}" var="names">
<option><c:out value="${names}"/></option>
</c:forEach>
</select>
The ${names} is a list of names from the database. I want to select an option dynamically in the drop down list. Suppose there are three names in the database Rohan, Dean, Justin. If Dean is logged, i want select the option Dean as selected.
I try a code like this but this does not work.
<option value="${names}" ${names == names ? 'selected' : ''}>${names}</option>
Try like this assuming that loggedInUser variable holds the String value of the currently logged in user.
<select id="names" name="names">
<c:forEach items="${names}" var="names">
<c:when test="${loggedInUser eq names}">
<option value ="<c:out value="${names}"/>" selected="selected">${names}</option>
</c:when>
<c:otherwise>
<option><c:out value="${names}"/></option>
</c:otherwise>
</c:forEach>
How to compare the strings in JSP EL. I tried to do
<select name="groupa" style="width: 170px">
<option value ="-1">no group</option>
<c:forEach var="gr" items="${sessionScope['entrantsAcceptor'].groups}">
<option value="${gr.idGroup}" <c:if test="${gr.code == param.group}">checked</c:if> >${gr.code}</option>
</c:forEach>
</select>
But it doesn't work(there are no any checked in options of select(though I pass correct argument)). Also I have tried to do
${gr.code eq param.group}
but it also has no effect
The EL looks fine and should work fine. Rightclick the page in webbrowser and choose View Source. Do you see the checked attribute being set in the right place in the generated HTML?
But this is after all not the right attribute. On a HTML <option> element you need to set the selected attribute, not the checked attribute.
<c:if test="${gr.code == param.group}">selected</c:if>