I want to get the value from a select to a servlet. It works but not correctly.
<select name="type" class="txtBox">
<%while (rs2.next()) {%>
<%if (!rs2.getString("states").trim().equalsIgnoreCase("inactive")) {%>
<option value="<%=rs2.getString("loancode").trim()%>">
<%=rs2.getString("loanname").trim()%>
</option>
<%}%>
<%}%>
</select>
this code is after load to browser
<select name="type" class="txtBox">
<option value="VL">veheicle loan</option>
<option value="HL">housing loan</option>
<option value="EL">education loan</option>
</select>
It works OK, but after save to DB value from combo box saved value not loancode value .saved value is loanname value.
like this pic i want to save loantype as vehicle loan.but it save as 'veh'(option name first 3 character) i want save as 'VL'(value of option).but i can't imaging how to do this please help me to do this.
*loanename,loancode,loantype is my DB column
**sorry for my bad english
Related
I am trying to modify the option in Thymeleaf so that the table can show me only selected item, after clicking the option. Here is my code:
<th>
<select th:onchange="???" id="stateSelect" class="form-control" th:field="*{receiverType}">
<option th:value='NULL'>All aggregators</option>
<option th:each="receiverType : ${receiverTypes}"
th:value="${receiverType}"
th:text="${receiverType}">
</option>
</select>
</th>
I know that i should use onchange , but i am confused.
i want selected value in input text field in jsp how to do please help? I am new with jsp.
<select class="leavetype" name="leavetype">
<option value="10">CL</option>
<option value="7">ML</option>
<option value="12">SL</option>
<option value="20">EL/PL</option>
<option value="5">CPL</option>
</select>
<input type="text" name="leave"/>
See this video:- https://www.youtube.com/watch?v=89rRD04QZE4
Hope so it will help you.
In jsp page you may write. ${param.leavetype}.
You can achieve through javascript by using onChange function. Within in function need to do like this document.getElementById ("leave").value = data.value;
Refer this Answer
I try to load conditional value to a select tag based on the user's choice on a pervious form tag. it might require java or php. i am not competent in any of those two language.
the logic is explain as the following.
<form>
<input name="complaint" value="copyright" type="radio">copyright <br>
<input name="complaint" value="trademark" type="radio">trademark <br>
<input name="complaint" value="other_concern" type="radio"> other concerns
</form>
if complaint="copyright" then
<select>
<option value="image">image</option>
<option value="product">product</option>
</select>
elseif complaint="trademark" then
<select>
<option value="item">item</option>
<option value="image">image</option>
</select>
elseif complaint="other_concern"
<select>
<option value="explain">explain</option>
</select>
end if
any solution?
Heres a solution in Jquery. Add a class name to the inputs and hide the selct options by default
<input name="complaint" value="copyright" type="radio" class="complaint">
then add unique ID tags to the select options along with a css class i like to use, .addClass and .removeClass are slighty faster and more efficent than .hide() and .show() selectors
Add the css at the bottom of your css sheet
.hidden{position:absolute;width:0;height:0;overflow:hidden;visibility:0;padding:0;margin:0}
<select id="copyright" class="selectOptions hidden">
<option value="image">image</option>
<option value="product">product</option>
</select>
Finally add some JQuery You need to copy the remainder for your other hidden values
$('.complaint').click(function() {
$('.selectOptions').addClass('hidden');
var checkComplaint = $(this).val();
$('#' + checkComplaint).removeClass('hidden');
});
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
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>