Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Change the textfield caption at run time

Avatar

Former Community Member
Can I change the caption of a textfield at run time??



i.e lets say i click a button and the textfield caption changes from Text1 to text2
6 Replies

Avatar

Former Community Member
Yes, but it's not as obvious as changing a field's value.



The following script will change a field's caption on the click of a button but you must be previewing/saving as a
dynamic PDF or else all captions are static (can't be changed):



TextField1.caption.value.#text = "test";


Stefan

Adobe Systems

Avatar

Former Community Member
I am saving it as dynamic pdf but this code doesnt seem to work..

Thanks

marleen

Avatar

Former Community Member
I got it..the caption is now changing but I had to change the language in the scrip editor as formCalc to use the #text property..which i do not understand as Why?? can you please clarify that...

Avatar

Former Community Member
My form had two objects: A button and a text field (named TextField1). The script I last posted was on the button's Click event as FormCalc.



In the underlying XML, the field (TextField1) looks like this by default (I'm skipping stuff that isn't important in this case):



<field name="TextField1">



  <caption>



    <value>



      <text>Text Field

    </value>



  </caption>



</field>



When trying to access the field's caption, you need to get the value of the caption's text element.



The
#text property is accessing the <text> element contained within the caption's value element. In this case, you could probably simply use



TextField1.caption.value.text = "test"


and get the same results (without the "#" prefix). The use of "#" as a prefix on the
text property forces the scripting engine to look for an attribute or element by the name of "text" instead of first looking for a form object named "text". When you know that there's a specific attribute or element you're trying to access and it has the same name as an object on your form, it's safer to prefix the attribute/element name with "#" to ensure you get desired results.



Stefan

Adobe Systems

Avatar

Former Community Member
I'm sorry. I should've mentioned the script I specified was in FormCalc and not JavaScript.



The use of the "#" prefix on the
text property is only supported in FormCalc in the sense that only FormCalc is able to interpret the expression you're specifying including the "#".



It's possible to use the "#" prefix in JavaScript but you must use the
resolveNode method on the containing object in order to do so (because JavaScript as a language doesn't support the use of the "#" character in an expression):



TextField1.caption.value.resolveNode("#text").value = "test";


The
resolveNode method lets Acrobat support the use of the "#" character in expressions via its JavaScript scripting model.



Stefan

Adobe Systems

Avatar

Former Community Member
Thanks so much Stefan...It's all clear to me now..thanks for all your help