Skip to main content
Inspiring
February 11, 2020
Answered

How to underline part of text Javascript

  • February 11, 2020
  • 1 reply
  • 4536 views

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 has been closed for replies.
Correct answer shannonm52004285
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

1 reply

Bernd Alheit
Community Expert
Community Expert
February 11, 2020

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

Inspiring
February 11, 2020

How would that script look written out ?

Bernd Alheit
Community Expert
Community Expert
February 11, 2020

You can see a sample in the Acrobat Javascript Reference.