Copy link to clipboard
Copied
I would like to know if it is possible to underline a word within a text field. In my example below I want to underline the word MINOR: only.
This is my coding:
event.value="MINOR: " + this.getField(“BName”).valueAsString;
I want the above to look like this:
MINOR: Jane Doe
Is this possible?
Thank you
Copy link to clipboard
Copied
This is possible. Use rich text format in the text field and the JavaScript span object.
Copy link to clipboard
Copied
Thanks for your response Bernd, but I'm still at a loss on how to do this.
Can you help me out with the coding for this?
Copy link to clipboard
Copied
See the documentation at the link below
Example 1 will show you how to underline some text.
Example 2 shows you the rest of what you need to do to construct a set of span objects that have different formatting and then set that as the rich text value. In your use case, you'd need two spans.
Copy link to clipboard
Copied
Hi Joel, thank you for the link. In looking at the link you sent, I don’t want to underline the text field BName in my example, I want to underline the text I’m putting in front of the text field. And after reviewing the information you sent I still don’t know how to do this.
So my situation is this: my calculation script in text field Text 10 is:
event.value="MINOR: " + this.getField("BName").valueAsString;
I want MINOR: to be underlined not the text field BName
MINOR: Jane Doe
The info that you provided reads, to me, that the underline would be for the entire field of BName, which is not what I want.
Sorry, I’m not understanding the information you provided.
Copy link to clipboard
Copied
You'd create a span for "MINOR:" and set the properties to underline it. Then another span for the field value and set the properties for that.
Then you'll need to modify your calculation for Text 10 so that it sets the rich value of the field rather than the value of the calculation event. Use...
event.target.richValue = spans
...like in the example
Copy link to clipboard
Copied
Okay, below is what I got out of the information you provided.
var f = this.getField("Text10");
var spans = f.richValue;
spans[0].underline = true;
f.richValue = spans;
var spans = new Array();
var spans = new Object();
spans[0].text = "MINORS: ";
spans[0].underline = true;
event.target.richValue = spans;
And my result is an empty text field.
I don’t know who to utilize the information you provided for my situation. Would it be possible for you to provide me with the coding?
Copy link to clipboard
Copied
I could but you wouldn't learn anything for next time.
Take a look at this link and then revisit the problem.
Learning to Program JavaScript for Adobe Acrobat - KHKonsulting LLC
Copy link to clipboard
Copied
In the Acrobat JavaScript Reference look at the sample of the span object.