Currently, I am working on a project that involves creating a form with a dropdown field for categories. Based on the chosen category, I need to populate a second dropdown called subcaste using AJAX.
To achieve this, I have implemented a method that disables the sub caste dropdown when the selected category is "OPEN" as shown below:
if(str=="OPEN"||str=="open"){
document.form.subcaste.disabled=true;
}
However, upon hitting the submit button, I encounter a null pointer exception in the line:
subCaste = request.getParameter("subcaste");
This occurs in the servlet code where the value of subcaste from the JSP page is retrieved. Even after setting a default value for subcaste as "Select", I still face the null pointer exception. It seems that the disabled dropdown box doesn't pass the value back to the servlet.
The code snippets are as follows:
JSP:
<td id='category'><select name='category' onchange="showSubCaste(this.value);">
<option value="none" selected="selected">Select</option>
<% for (i = 0; i < categorySize; i++) {%>
<% category = (String) categoryArr.get(i);%>
<option value=<%= category%>><%= category%></option>
<% }%>
</select>
</td>
<td >SubCaste</td>
<td id='subcaste'> <select name='subcaste'>
<option value="none">Select</option>
</select>
</td>
JavaScript:
function showSubCaste(str){
...
if(str=="OPEN"||str=="open"){
document.form.subcaste.disabled=true;
document.form.issuingAuthority.disabled=true;
}
else{
document.form.subcaste.disabled=false;
document.form.issuingAuthority.disabled=false;
var url="SubCasteController";
url +="?caste=" +str;
...}
This leads to values being fetched in a servlet and passed onto another JSP using the following snippet:
<%String buffer = "<select name='subcaste' onchange='subCasteChanged(this.value);'><option value='none' selected='selected'>Select SubCaste</option>";
for (int i = 0; i < sizeInfo; i++) {
subCaste = (String) retrievedInfo.get(i);
buffer = buffer + "<option value='" + subCaste + "'>" + subCaste + "</option>";
}
buffer = buffer + "</select>";
response.getWriter().println(buffer);
%>
I'm currently stuck at this point and would greatly appreciate any assistance or guidance on how to proceed further. Thank you in advance.