Then in controller/servlet you will receive the id of TaxiInfo:
String val = request.getParameter("taxiDropdown");
System.out.println(val);
Or in your case you should set a hidden input with javascript with desired value.
Solution 2 :
added this code in html:
Move value of the dropdown selection to hidden textbox
<script type='text/javascript'>
$(function() {
$('#driverdp').change(function() { <-- this is my dropdown -->
var x = $(this).val();
$('#driverid').val(x); <-- this is my textbox -->
});
});
</script>
Servlet:
get the value of hidden text in servlet
String text= request.getParameter("driverId");
hope it will help someone
Problem :
I have dropdown with options and the values. I can get the option value by the dropdown name in servlet but how can i get the dropdown “value” in servlet. In screenshot, temporarily i concatenated the with options but i want to store value in variable in servlet.
Please help:
String val = request.getParameter("taxiDropdown");
(in “val”, I want to store the value of the dropdown not the option text)
Comments
Comment posted by Swati
do you need
Comment posted by Eddie
Absolutely right, how can i get that? so dropdown option giving me 1076(name in table) and value give me (1(ID in table)
Comment posted by Swati
when you select any option from dropdown what does
Comment posted by Eddie
Thanks, another person said, i couldn’t get the “Value”(input name=”text” value=”123″) without putting in html. As you see in brackets, i am trying to get “123” with getParameter which is not possible i think.
Comment posted by Eddie
so you saying, there is no way to get value=”<%=taxiInfo.getID()%>“> in request.getParameter without hidden input?
Comment posted by Getodac
Yes, as I know, you can’t get the value of taxiInfo.ID without using a classic html select, or with a hidden input that you set with javascript.
Comment posted by Eddie
Good to know, i added hidden field and get the value. thank you