• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

multibox disabled but checked

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
That which doesn't kill us makes us stronger. I think a piece of pie wouldn't kill me. Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic