Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts 2 - disable a checkboxlist using javascript

 
Rodrigo Bossini
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm using struts 2 on a web project I'm working on. I'm new at web development.

I'm using a struts 2 tag, checkboxlist, to give the user some options to select.


I have also a radio, which when clicked should enable or disable the checkboxlist, depending on the choice made by the user.

The problem is that I can't seen to do it by using javascript.

I have a script that disables text fields, radio fields, but that can't disable the checkboxlist.

Has anyone seen this issue before?
 
Dejan Mratinkovic
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This is more of java script than java question. Check http://cn.w3schools.com/jsref/prop_checkbox_disabled.asp, there you will find working example how to disable check box.

You should see how struts renders your check box (depends on theme you choose), and then figure out how to write java script for it.

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As the previous poster implies, you'll actually need to disable each individual checkbox--HTML doesn't have the concept of a "checkbox list".

The code would be a one-liner using jQuery, Prototype, or similar.
 
Rodrigo Bossini
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you guys have a suggestion on how to disable the components using something other than pure javascript?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't possibly see how--you're trying to act on an event, and that means JavaScript.

Another option would be to submit the form and redraw the entire page, checking a flag to see if the radiobox list should be rendered as disabled or not.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic