This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "multibox disabled but checked" Watch "multibox disabled but checked" New topic
Author

multibox disabled but checked

Janhvi Malhotra
Greenhorn

Joined: Jan 12, 2006
Posts: 6
Hi,
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 ?

Thanks
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?

Thanks,
Eric
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.


Merrill
Consultant, Sima Solutions
Janhvi Malhotra
Greenhorn

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: http://aspose.com/file-tools
 
subject: multibox disabled but checked
 
Similar Threads
how to disable if one or more check boxes selected
checkbox in jsp
Problem in request.getParameterValues()
slow for loops inside javascript..
checkbox must always be checkd