Skip to content Skip to sidebar Skip to footer

Button Magic

7 Comments

  • Gordon McLean
    Posted January 16, 2014 at 8:59 am

    This may be a super obvious question Gary but it there a way to show these css buttons as clicked ie get Servoy to change the button state to active or similar ?

    • Post Author
      Gary Dotzlaw
      Posted January 16, 2014 at 1:52 pm

      It’s actually not as easy as you would think. I have done this using JQuery and CSS, but it takes some work (you decide if it is worth it; I stay away from it). You do it like this:

      1. Create your three CSS classes for the various button states

      button
      {
          //your css
      }
      .button:active
      {
          //your css
      }
      .button:hover
      {
          //your css
      }

      2. Use JQuery to change the class (example shown only makes it active, so you need to modify to check for class and set active/normal), or use JQuery to locate your button by name and change the class (you might do this in the fireEvent handler of the button):

      $(document).ready(function(){
          $('.button').click(function(){
              $(this).toggleClass('active');
          });
      });

      Read Docs http://api.jquery.com/toggleClass/

      • Gordon McLean
        Posted January 17, 2014 at 10:13 am

        Thanks Gary, I suspect there would also be some mileage in looking at AngularJS for a similar solution that may be easier to implement. I think your right about the is it worth it question; perhaps not .. !!

        • Post Author
          Gary Dotzlaw
          Posted January 17, 2014 at 1:34 pm

          Yes, I think for normal buttons, just a hover state is all that is needed; skip the “active” state to indicate the button has been pressed. Setting a normal button to a state that indicates it has been pressed, later causes problems because you have to again reset it at some point. This type of on/off behavior is better suited to radio-buttons, which can be made to look really nice with CSS (like actual on/off toggle switches) instead of the basic Servoy radios.

  • James Doonan
    Posted August 2, 2016 at 2:48 pm

    Hi Gary,

    Your tutorials are great, thanks for the time and effort you put in. It helps me a lot.Quick question if you have the time to answer:

    I am using the following code to set the state of a selected button:

    forms.frm_main.elements[‘btn_’ + globals.g_globals_section].border = ‘SpecialMatteBorder,0,0,5,1,#3c9be9,#3c9be9,#3c9be9,#e0e0e0,2.0,’;

    Can I use similar code to set the state of the button on mouse rollover? I have tried several different approaches but none of them are working for me?

    Thanks

    • Post Author
      Gary Dotzlaw
      Posted August 3, 2016 at 12:55 pm

      Hi James,

      Thanks for the feedback on the tutorials. I wish I had time to write again.

      Sorry to say, I have never tried what you are asking, so I have no suggestions.

      • James Doonan
        Posted August 4, 2016 at 9:07 am

        No problem,

        Thank you for the reply.

Leave a comment

Dotzlaw © 2025. All Rights Reserved.