I have a dropdown menu which pulls data from a SQL table. Everything works fine and I'm able to select the value and submit the form. However, my scriptlet gives NULL exception when I convert the value from String. What am I doing wrong?
testCars.jsp
<form method=post action=“testCars.jsp">
<div class="cell">
Select CarID
<div class="input-control select mutiple full-size">
<select id=“carID” name=“carID” onchange="listCarIDFromDatabase();”>
<option selected disabled>--SELECT--</option>
<%
ArrayList<Integer> result = carDAO.getCarID(Integer.parseInt(id));
for (int r: result){
out.println("<option value='" + r + "'>" + r + "</option>");
request.setAttribute("r", r);
}
%>
</select>
</div>
</div>
The input returncarID is populated based on AJAX success onchange="listCarIDFromDatabase();
<button class="button primary" type="submit">Generate</button></form>
<input name=“returncarID” id=“returncarID”>
<%
//Scriptlet gets the value of the dropdown in next line, but when I convert to Int it is NULL
String y = request.getParameter(“returncarID”);
out.println(y); <——Prints out value here
int x = Integer.parseInt(y);
out.println(x); <———Null Exception here
%>