Hi ,
I have a JSP page where i have few checkboxes and i have disabled few of them usign javascript for certain conditions.
When i fetch the value from checkbox using request.getParameterValues("CheckBoxName"); , then do i get the values from disabled checkboxes too or disabled checkboxes are not considered by java when we fetch value?
Here is the code , checkbox with id s1 and s2 are dibaled using javascript

<form action="booking_cnf" method="post">
<!--  checkbox id is same as the value of SeatNo in the database -->
<!--  checkbox with id=1 and id=2 are disabled using javascript -->
<input type="checkbox" id="s1" name="seat" value="s1">
<input type="checkbox" id="s2" name="seat" value="s2">
<input type="checkbox" id="s3" name="seat" value="s3">
<input type="checkbox" id="s4" name="seat" value="s4">
<input type="hidden" name="doj" value="<%=doj%>">
<input type="hidden" name="BusNo" value="<%=BusNo%>">
<input type="submit" value="book">
</form>

Now the action class or model has the followind code

String BookSeats[] = request.getParameterValues("seat");
  if(BookSeats !=null){

      for(int i=0; i<BookSeats.length; i++){
          System.out.println(BookSeats[i]);
          //here i will insert the seats in database which are selected in checkboxes
      }
  }

Can i do this ?
I am confused , what happends with the disabled checkboxes?

Please Help

Dani AI

Generated

Short answer: disabled checkboxes are not submitted. Only checked, enabled inputs with the same name appear in request.getParameterValues("seat"). So in your example, if s1 and s2 are disabled, they will never be in the seat array; unchecked boxes are also omitted. This is by design per the HTML form rules. (developer.mozilla.org)

If you need to show a box as selected but unchangeable and still send its value, do not rely on readonly (it does not apply to checkboxes). Instead, pair a disabled, checked box with a hidden input that mirrors the value. (html.spec.whatwg.org)

<input type="checkbox" name="seat" value="s2" checked disabled>
<input type="hidden"   name="seat" value="s2">

That pattern preserves the value on POST while keeping the UI locked.

On ’s alternatives: enabling all fields on submit works if your goal is to include prechecked-but-disabled values, but be careful not to re-enable seats you intended to block. If you go that route, mark only the ones you want to include and enable just those on submit:

form.addEventListener('submit', () => {
  document.querySelectorAll('input[type=checkbox][data-include][disabled]')
    .forEach(cb => cb.disabled = false);
});

Finally, for a booking flow, never trust the client to enforce availability. Treat the DB as the source of truth: on submit, re-check that each requested seat is still free and reserve it atomically (transaction or unique constraint). That prevents someone from re-enabling a disabled seat in DevTools and posting it anyway.

Disabled check boxes to not send their data on POST. Few alternatives:

1) Keep a hidden element with the check boxes with the same value.
2) Use javascript to enable all the check boxes on submit before the data is sent so they are included
3) Use CSS and JS to emulate a disabled box (prevent default event) without actually disabling them

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.