javascript to change caption on a field

3,458 views
Skip to first unread message

Amal Elaine

unread,
May 2, 2009, 5:49:59 PM5/2/09
to Adobe LiveCycle Developers
Can you use javascript to change the caption on a field at run time?  If so, can you provide a quick example?
 
Thanks,
E

--
Amal Elaine Photography
http://www.pbase.com/amal007

Brian Ghigiarelli

unread,
May 2, 2009, 7:48:54 PM5/2/09
to live...@googlegroups.com
Yup!  It's the [field].caption.value.text.value property.  For example:

xfa.resolveNode("nameTextBox").caption.value.text.value = "Your Name:";

Take care,
Brian
--
Brian Ghigiarelli
570-878-9139

Amal Elaine

unread,
May 2, 2009, 9:58:04 PM5/2/09
to live...@googlegroups.com
Thanks Brian!
 
I tried xfa.resolveNode("nameTextBox").caption.value="Your Name", but that didn't work.  How does one know that they need to also do a ".text.value"? 
 
Which leads me to another question, but I'll post a new thread on that one...stay tuned.
 
Thanks again!
E

Bob Bailey

unread,
May 4, 2009, 9:51:02 AM5/4/09
to Adobe LiveCycle Developers
I just tried this script and it seemed to work.

this.parent.resolveNode("TextField1.caption.value.#text").value ="New
Caption Value";


Bob



On May 2, 9:58 pm, Amal Elaine <amalela...@gmail.com> wrote:
> Thanks Brian!
>
> I tried xfa.resolveNode("nameTextBox").caption.value="Your Name", but that
> didn't work.  How does one know that they need to also do a ".text.value"?
>
> Which leads me to another question, but I'll post a new thread on that
> one...stay tuned.
>
> Thanks again!
> E
>
> On Sat, May 2, 2009 at 7:48 PM, Brian Ghigiarelli <briang...@gmail.com>wrote:
>
>
>
> > Yup!  It's the [field].caption.value.text.value property.  For example:
>
> > xfa.resolveNode("nameTextBox").caption.value.text.value = "Your Name:";
>
> > Take care,
> > Brian
>

Duane Nickull

unread,
May 4, 2009, 11:39:12 AM5/4/09
to live...@googlegroups.com
Alternatively, you can leave the caption blank and use a label (with visible toggled) as a second way to accomplish this.

D

--
Sr. Technical Evangelist – Adobe Systems
Chair – OASIS SOA RM Technical Committee
Manager – Adobe LiveCycle ES Developers List
Blog: http://technoracle.blogspot.com
Twitter: duanechaos
TV Show: http://www.duanesworldtv.org
Band: http://www.myspace.com/22ndcentury

Amal Elaine

unread,
May 4, 2009, 12:51:21 PM5/4/09
to live...@googlegroups.com
Thanks Bob,  what is the significance of the pound sign?

Bob Bailey

unread,
May 4, 2009, 1:33:34 PM5/4/09
to Adobe LiveCycle Developers
It looks like it works without the #. I just found this example and
posted it. The only time I have used the # in script is when I had a
form level variable with the same name as an object property (I try to
avoid doing this now). The # tells the script to access the property
value and not the object with that name.


Bob


On May 4, 12:51 pm, Amal Elaine <amalela...@gmail.com> wrote:
> Thanks Bob,  what is the significance of the pound sign?
>

Amal Elaine

unread,
May 5, 2009, 1:57:30 PM5/5/09
to live...@googlegroups.com
Interestingly enough, this code seems to work properly on a text object, but not on a text field object.  Is there something I'm doing wrong?

script (right out of the scripting documentation under designer help, my field on the form is called "textField" too):

xfa.resolveNode("textField.caption.value.#text").value = "Alternate Caption:";

My form is interactive and dynamic xml...

Thanks
E

Elaine

unread,
May 5, 2009, 2:10:20 PM5/5/09
to Adobe LiveCycle Developers
I think there's something going on with the field, because when I
manually changed the caption in the object palette I received a
message that the "rich text formatting" would be lost... But that
didn't happen all other text fields.... Not sure...

Bob Bailey

unread,
May 5, 2009, 3:25:09 PM5/5/09
to Adobe LiveCycle Developers
It definitely works for a text field. I even set the formatting to
rich text and it still worked. Not sure what is happening on your
form. Did you try deleting the object and then re-adding it?


Bob

Amal Elaine

unread,
May 6, 2009, 7:38:58 AM5/6/09
to live...@googlegroups.com
Well, this situation happened twice for both of us working on separate forms... initially the javascript would not change the caption, so in Designer, we went to the object palette of the field, removed the "caption" text (where we received the message about "losing the rich text formatting"), then we clicked ok, added new default text in the caption of the palette, and previewed the form again and it worked.

So we got it to work, but it was rather quirky.  Thanks for your feedback!
E
Reply all
Reply to author
Forward
0 new messages