File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes multibox disabled but checked Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "multibox disabled but checked" Watch "multibox disabled but checked" New topic

multibox disabled but checked

Janhvi Malhotra

Joined: Jan 12, 2006
Posts: 6
I am displaying a list of checkboxes where some are selected by default and the user cannot uncheck them..So I set the disabled= true attribute for those checkboxes.
When I do a form submit, the values of the disabled checkboxes are not sent
even though they are checked...

How to gracefully solve this ?

Eric Gero
Ranch Hand

Joined: Jul 20, 2005
Posts: 73
I am no expert in Struts, but I thought this was an interesting question. When a multibox is sent, the clients browser recieves a list of checkboxes like
<input type="checkbox" name="chkBox" value="white" checked="true" disabled="true">
<input type="checkbox" name="chkBox" value="black" checked="true" disabled="true">
<input type="checkbox" name="chkBox" value="blue" checked="false">
<input type="checkbox" name="chkBox" value="green" checked="false">

The values of the checked but disabled checkboxes are available to javascript. So, couldn't you cycle through the checkboxes with chkBox[i] and rebuild the URL before the form is submitted? It may not be the fanciest solution, but I think it should work. Maybe someone more experienced in Struts could tell us if this is not a good idea?

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Unfortunately, disabled inputs don't submit a value. The method suggested by Eric will work. Here are a couple more possible workarounds:

For each disabled checkbox, create a <html:hidden> field with the same property name. The hidden control will be submitted.

Another possibility would be to use javaScript to re-enable the checkboxes just before the form is submitted.

Consultant, Sima Solutions
Janhvi Malhotra

Joined: Jan 12, 2006
Posts: 6
Thanks Guys,

the work around I have is, since the server already knows the defaultchecked checkboxes, I add them to what the user selected..
I agree. Here's the link:
subject: multibox disabled but checked
It's not a secret anymore!