Skip to main content
Inspiring
February 11, 2020
Answered

How to underline part of text Javascript

Hi: I am trying to figure out a way to underline only part of a "string" (if i'm using that correctly) I have a paragraph that auto populates based on a custom calculation script. 

I used the follwoing in the script in the custom validation script section wich underlines the whole paragraph. I would like to only underline the first two words of the paragraph. 

var span1 = {};

span1.text = event.value;

span1.underline = true;

event.richValue = [span1];

 

Any suggestions or solutions. Thank you ! 

 

 

This topic is closed to new replies. Start a new post to keep the conversation going.
shannonm52004285Correct answer
Inspiring
February 11, 2020
event.richValue = [span1,span2];

That's what arrays are for, making lists of things 😉

 


var span1 = {};
span1.text = event.value;
span1.underline = true;
var span2 = {};
span2.text = event.value;
span2.underline = false;
event.richValue = [span1,span2];

this works but its duplicating everything, so everything is underlined and then repeated not underlined

11 replies

Bernd Alheit
Community Expert
Community Expert
February 11, 2020

Use 2 spans. One for the first two words. The other for the rest.

Translate
Inspiring
February 11, 2020

How would that script look written out ?

Translate
Bernd Alheit
Community Expert
Community Expert
February 11, 2020

You can see a sample in the Acrobat Javascript Reference.

Translate