Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6115957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:09:05+00:00 2026-05-23T15:09:05+00:00

I am working on a project in which I need to create a form

  • 0

I am working on a project in which I need to create a form with a dropdown field for category. And according to the category selected, I have to populate the second drop down called subcaste.
This I am achieving through AJAX.

I also wrote a method which will be called on change of the category to disable the sub caste dropdown box if the selected category is OPEN as:

if(str=="OPEN"||str=="open"){
        document.form.subcaste.disabled=true;
} 

But when I hit the submit button, i get a null pointer exception in the line:

subCaste = request.getParameter("subcaste");

in the servlet. (This line takes the value of the subcaste from the jsp page).

I have also done: <option value="none" selected="selected">Select</option>
in the drop down of the subcaste so that a default value is selected. But I still get a null pointer exception. I believe that after I disable the dropdown box, the value isnt available to the servlet at all.

The detailed code is:

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;
...}

After retrieving the values in a servlet and passing it to another JSP:

<%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 do not know how to proceed with this. Please help me.

Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:09:06+00:00Added an answer on May 23, 2026 at 3:09 pm

    Yes , you are right . If the <select> is disabled , its values will not be POSTED. So when you get its value using request.getParameter() , it will return null pointer exception.

    The standard practices to get a disabled <select> to post its value are

    • Add a hidden input field that will submit the same value and copy the value from the disabled <select> to this hidden field in the <form> ‘s onsubmit() event

    or

    • Re-enable the disabled <select> in the <form> ‘s onsubmit() event

    Or alternatively , as you believe the null pointer exception is because subCaste is set to null ,you can try to to set subCaste variable to some specific value if the subCaste parameters is null to see if it can be solved.

    if (  request.getParameter("subcaste") != null){
        subCaste = request.getParameter("subcaste");
    }else{
       subCaste = "xxxxx"; //set to a  specific value according to your requirement. 
    }
    

    Reference

    HTML form readonly SELECT tag/input

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a project which I need to create a custom voice
I'm working on a project in Rails 3 where I need to create an
I'm currently working on a project for which I need two sliders.. Currently I'm
Im currently working on a small project in which I need to model the
I'm working on a small Google App Engine project in which I need to
I'm currently working on a project in which i need to read some (Latitude,
I am working a project where i need to create a state machine work
I'm working on a project which is just about to start, and since I
I'm working in a project which needs to clean up some third party XSD
I am working on a project which uses an import #import progid:Blah.blah.retrieve rename_namespace(Blah) but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.