I'm currently working on a project using JSP and Servlets. On one of the pages, there is a dropdown list and I need to check if the selected value is present in the database. Right now, it only checks when I click a button but I want it to check whenever the value in the dropdown list changes.
For example:
<select id="abc">
<option value="1">test1</option>
<option value="2">test2</option>
<option value="3">test3</option>
</select>
So far, I've used JavaScript like this:
<script>
var e = document.getElementById("abc");
var str = e.options[e.selectedIndex].text;
</script>
Now, how can I check the value of 'str' in the database within JSP?
I believe it can be done with JavaScript, but I'm not certain. Also, I'm unsure how to check the database value in a script tag. It may involve AJAX as well. Please provide some guidance.