Changing the Button Text - InfoPath Dev
in

InfoPath Dev

Changing the Button Text

Last post 10-23-2008 08:26 AM by Jimmy. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 10-21-2008 02:09 PM

    • mjm917
    • Not Ranked
    • Joined on 08-22-2008
    • Naperville, IL
    • Posts 16

    Changing the Button Text

    I want to change the text of one of the form buttons (ID = btnShowAllExamples) from "Show" to "Hide" so that I can use it as a toggle.
    How do I get a reference to the button in the jscript onClick event

    I have probably overthought this and need someone to point me in the right direction again.it

    Thanks in advance.

    Thx

    mjm917
  • 10-21-2008 10:27 PM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: Changing the Button Text

    Hello,

    Depends on your condition you can change the text of the button as below,

    if(<Condition to change the text>)

    {

              btnShowAllExamples.value = "Hide";

    }

    else

    {

              btnShowAllExamples.value = "Show";

    }

  • 10-22-2008 06:07 AM In reply to

    • mjm917
    • Not Ranked
    • Joined on 08-22-2008
    • Naperville, IL
    • Posts 16

    Re: Changing the Button Text

    That is what I thought as well. My initial tests used the following code:

    btnShowAllExamples.value = 'Hide All examples';
    XDocument.UI.Alert(btnShowAllExamples.value);

     Which resulted in an Object doesn't support this property or method error. If I just use the alert statement, it is blank

    Here is the code I "want" I should be using based off of previous experience with javascript.

    if (btnShowAllExamples.value == 'Show All Examples')
       btnShowAllExamples.value = 'Hide All examples';
    else
       btnShowAllExamples.value = 'Show All Examples'; 

    I can't be the first person who has wanted to do this. 

    I should clarify that I am using IP 2003. When you look at the button properties the "text" is stored in the "label property."

    Also, I never thought I would say this but... Is there anyway to get intellisense to work in IP2k3? 

    Thx

    mjm917
  • 10-23-2008 08:26 AM In reply to

    Re: Changing the Button Text

     The following would work, and involves no code.

     Add two new fields to your form, a boolean field called shown and a text field called buttonText.  In the control properties, set the button's text to be the value of buttonText.  Set the default value of buttonText to be "Show" and the default of shown to be false.

    Now add these rules to the button:
    Rule 1 (condition: shown = "false"): Set shown to "true" and set buttonText to "Hide" (check "Stop processing rules when this rule finishes")
    Rule 2 (condition: shown = "true"): Set shown to "false" and set buttonText to "Show"

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.