How can I get the current value of a selected dropdown list value using Javascript?
I have a user contact form in which I have a dropdown list and the value selected in the list must be captured by javascript function and then pass this value to the controller and set the bean value and then persist the value in database.
The list is like,
<select id="ddl">
<option value="val1">Optoion 1</option>
<option value="val2" selected="selected">Option 2</option>
<option value="val3">Option 3</option>
</select>
To return the string from the list
var e = document.getElementById("ddl");
var selected = e.options[e.selectedIndex].val();
Which would make selected be val2
How do I access this value in Java class and store the value in database?
I handled the request with ajax call and transferred control to a Spring Controller..I wrote this code in my controller..
and now finally that works as expected…