Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multibox disabled but checked

 
Janhvi Malhotra
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Janhvi Malhotra
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Guys,

the work around I have is, since the server already knows the defaultchecked checkboxes, I add them to what the user selected..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic