title: Changed select on jsp get null value in servlet
body: <p>I have a jsp page with a number of selects that are <strong>populated using</strong> <strong>jQuery</strong> i.e. they have the <code>&lt;option&gt;</code> tags, they just get it via a function. Each select has some 30 options each.</p>
  
  <pre><code>&lt;form id="target" name="target" action="/project/myservlet" method="get"&gt;
  &lt;select class="myClass" id="sel1" name="sel1" &gt;&lt;/select&gt;
  &lt;select class="myClass" id="sel2" name="sel2"&gt;&lt;/select&gt;
  ...
  &lt;/form&gt;
  </code></pre>
  
  <p>I received these values in my servlet using <code>request.getParameter("sel1")</code> but I'm getting null for the selects that are changed. As in, say I select values from the 2nd, 4th and 5th selects, then these selects get null values in the servlet. Others get the 0th value (default and unchanged) - which is okay.
  <a href="https://stackoverflow.com/questions/14728297/reqest-getparameter-returns-null-for-select-box-in-jsp">This</a> can help explain my question. I'm getting null in the next page when I modify the select.</p>
  
  <p>According to this, if I use <code>onload</code> in select, it helps take the updated values to the next page for ONE select. But the problem is that I don't just have one select on the page. I want the updated values to go the next page without a page refresh/going to another page, unless submit for them is clicked. I think the request is not getting updated when the change takes place? Even the url in "get" doesn't get the changed selects.</p>
  
  <p>There is no error as such, just that I am getting the values if the selects are unmodified (defaults). It sends the default values to the next page. When I select another option from the drop down, I get null on the servlet unless I use <code>onchange</code>to submit the form. But that doesn't work for me since I have many selects. I can't keep submitting the form and going to the next page on every select change.</p>
  
  <p>EDIT:
  If it helps, here is my jQuery code:</p>
  
  <pre><code>$(document).ready(function() {
  
                  $('select').change(function(){
                      var v = $(this).val();
                      $('select option[value="'+$(this).data('old-val')+'"]').prop('disabled', false);
                      $(this).data('old-val',v);
                      if(v != "0"){
                          $('select option[value="'+v+'"]').not(this).prop('disabled',true);
                      }
                  });
  
                  $('select').each(function(idx,select){   
                      var stateArray = ["Preference No. "+(idx+1),"Bill", "Sally", "Alice"];
                      $.each(stateArray, function(iIdx, iItem){  
                          $(select).append('&lt;option value="'+iIdx+'"&gt;'+iItem+'&lt;/option&gt;');
                      });
                  });   
  
                  $( "#target" ).submit(function( event ) {
                      alert( "Handler for .submit() called." );
                  });
  
              });
  </code></pre>
  
  <p>EDIT 2: Servlet:
      public class Preference extends HttpServlet {</p>
  
  <pre><code>protected void processRequest(HttpServletRequest request, HttpServletResponse response) {
      response.setContentType("text/html;charset=UTF-8");
      try {
               PrintWriter out = response.getWriter();
               String sel  =  request.getParameter("sel1");
           }catch(Exception e){ }
     }
  }
  </code></pre>