Results 1 to 5 of 5

Thread: Enabled and Disabled Button Properties

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,754

    Enabled and Disabled Button Properties

    I need y'all's opinion on how to tackle an issue. I have a button(<input type="button">) that I need to be enabled or disabled dependent on the value of a dropdown. One option I was thinking was to create two different classes, one for the enabled and the other for the disabled, and once the dropdown option changed I would set the class of the button equal to the enabled or disabled CSS style using JavaScript. The other option I was thinking about doing was creating two separate buttons, one for enabled and one for disabled, and showing/hiding the button when the dropdown option is changed, again using JavaScript.

    I wanted to know if there was a better option than these two, perhaps an option that just uses CSS rather than JavaScript. Any suggestions are appreciated.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Enabled and Disabled Button Properties

    As far as I know, you can't disable a button using CSS.

    Is there any reason you're not just toggling the disabled attribute of a button/input to disable/enable it?

    http://www.w3schools.com/tags/att_button_disabled.asp

    http://www.w3schools.com/tags/att_input_disabled.asp

  3. #3

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,754

    Re: Enabled and Disabled Button Properties

    Because I want for the button to have different styles whenever it is enabled/disabled. For example, while its enabled I want it's cursor to be Pointer and it's background color to be Green but while its disabled I want the cursor to be Default and it's background color Grey.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  4. #4
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: Enabled and Disabled Button Properties

    kfcSmitty is right. There is no way to "disable" or "enable" a button via CSS. You need to use JavaScript to toggle the disabled attribute of the button/input.

    For the CSS, just style the appropriate enabled and disabled pseudo-classes. No adding/removing of extra class names required. Just toggle the attribute and the CSS should update automatically.

    I normally prefer to use <button> elements over <input>, but that's just a personal preference. Makes no real difference in practice if you don't need the extra styling/html capabilities of <button>.
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  5. #5
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Enabled and Disabled Button Properties

    And here's the example I made: http://jsfiddle.net/m8hqjLr9/


    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width