Skip to main content
Inspiring
February 11, 2020
Answered

How to underline part of text Javascript

  • February 11, 2020
  • 1 reply
  • 4565 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 ?

Thom Parker
Community Expert
Community Expert
February 11, 2020

It didn't work ... this is my current script in the custom calulation script

var a = this.getField("options").value;
if(a == "a"){
event.value = "model a underlined title ..... model a  paragraph....";
}
else if(a == "b"){
event.value = "model b paragraph....";
}

in the custom validation I have 

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

what do I do to get just the first few words underlined ?


Create a separate span for just those two words.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often