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

Change the color of a button when it is Enable/Disable

 
Sam Saha
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using two different styleclass(commandExButton, commandExButtonDisabled). I am using a button which becomes Enable and Disable according to the conditions. Now when the button becomes Enable I want to use the "commandExButton" styleclass which will turn the letters of the button to white color. And when the button Disable I want to use the "commandExButtonDisabled" which will turn the letters of the button to grey color.

Now all the time(Enable/Disable) the letters of the button are grey because I can use the one condition. I am not sure how to use two conditions to disaplay the letters of the button white(commandExButton) when button is Enable else display Grey(commandExButtonDisabled). I am using jquery for that. I would appreciate if someone can help me on this as I am new in jquery. Thank you very much.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't use two "opposite" classes like this. Rather, I'd use one base class that's applied to all buttons, and another class for the disabled buttons that overrides the values in the base. That way, you never have to worry about removing any but the class for the disabled buttons.

For example, in the CSS:
The baseButton class is applied to all buttons. The disabledButton class is applied and removed as appropriate.


Of course this is all moot if all your supported browsers support CSS3 where you can do this completely with CSS.
 
Sam Saha
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I am very new in jquery, I would appreciate if you could explain how to use use one class for all(including Enable) and remove that class and add another class when the button is Disable.
 
Sam Saha
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using two different styleclass(commandExButton, commandExButtonDisabled). I am using a button which becomes Enable and Disable according to the conditions. Now when the button becomes Enable I want to use the "commandExButton" styleclass which will turn the letters of the button to white color. And when the button Disable I want to use the "commandExButtonDisabled" which will turn the letters of the button to grey color.

Now all the time(Enable/Disable) the letters of the button are grey because I can use the one condition. I am not sure how to use two conditions to disaplay the letters of the button white(commandExButton) when button is Enable else display Grey(commandExButtonDisabled). I am using jquery for that. I would appreciate if someone can help me on this as I am new in jquery. Thank you very much.


 
Jonas Isberg
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Did you try Bear's code? What happened?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic