How: ToggleButton javascript event handler to detect state (checked/unchecked) RRS feed

  • Question

  • Hi

    I have added a ToggleButton to the Ribbon of an entity. This works well. I can click the button and he is displayed as checked. Clicking once again displays the button as unchecked. Also the click event is called if I use a basic javascript method like the following:

    function buttonClicked(){


    Now the question is:

    How can I check if the button is checked or if the button is unchecked in the javascript method? Are there some parameters I'm missing yet giving me the checked state or do I have to access the button in the ribbon and check a property? Documentation about ToggleButton seems not to contain informations about this.

    Thanks for your answer

    Wednesday, August 14, 2013 6:50 AM


  • Hi,

    You need to configure your command to pass a CrmParameter:

            <JavaScriptFunction FunctionName="MyToggleFunction" Library="$webresource:MyWebresource.js">
              <CrmParameter Value="CommandProperties" />

    In your toggle function you can then get access to the state using this parameter:

    function MyToggleFunction(commandProperties)
     var checked = commandProperties.On==true;

    If you want to define a function that sets the initial value when you first open the form, you'll need to define a 'PopulateQueryCommand':

    function MyToggleQueryCommand(commandProperties){
        commandProperties["On"]=<Some expression>;


    Scott Durow
    Blog www.develop1.net    Follow Me
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Wednesday, August 14, 2013 9:40 AM