Skip to main content
Known Participant
September 16, 2024
Question

Bold, Underline and format text in javascript

  • September 16, 2024
  • 1 reply
  • 3847 views

Good morning all , I have the below script and would like to know how , if at all possible, if i can underline and bold some of the information in the JS below as well as formatting the phone numbers to read "(123) 456-7890" or similar . As of right now the phone number are reading" 1234567890"

Currently the scrupt is triggered via a button commant 

JS:

(I have bolded and underlined what i am trying to accomplish in the script)

Thank you for any help or guadance you are able to provide. 

//

var w1 = this.getField("DD_Writer").valueAsString;
var w2 = this.getField("Calc_WriterPosition").valueAsString;
var w3 = this.getField("Calc_WriterPhoneNumber").valueAsString;
var w4 = this.getField("Calc_WriterEmail").valueAsString;
var s1 = this.getField("DD_Secondary").valueAsString;
var s2 = this.getField("Calc_SecondaryPosition").valueAsString;
var s3 = this.getField("Calc_SecondaryPhoneNumber").valueAsString;
var s4 = this.getField("Calc_SecondaryEmail").valueAsString;
var m1 = this.getField("Date_LetterDate").valueAsString;
var m2 = this.getField("DD_SMQuarter").valueAsString;
var m3 = this.getField("DD_SMYear").valueAsString;
var m4 = this.getField("Date_DocDueDate").valueAsString;
var r = this.getField("Calc_Text");


r.value = "\n" + m1 + "\n\n\nDear,  Participant" +

"\n\nI hope this letter finds you well." +

"\n\nEach quarter NA is required to collect receipts from each participant for services you have received outside of NA. This includes billing statements from service providers such as doctors, dentists, and hospitals. From insurance companies it is called an “explanation of benefits”. If you have an in home care giver or COPES worker, we need a current award letter." +

"\n\nPlease reach out to any service providers you have utilized in the months of " + m2 + " " + m3 + " and request receiptsfor the services you used." +

"\n\nI have included a letter for you to show your provider in an effort to collect the documentation we need." +

"\n\nDue to privacy laws, NA cannot request this information directly from the provider. However, we want to support your effort as much as possible" +

"\n\nAll documentation is due to " + s1 + " ,or myself by " + m4 + "." +

"\n\nIf you need any assastance or have questions about what services qualify please reach out to us. " + s1 + " can be eached at " + s4 + " or by phone at " + s3 + "." + "I can be reached at " + w4 + " or by phone at " + w3 + "." +

"\n\nBy meeting our service match obligation, we can ensure funding for our housing voucher. We can do this together!" +

"\n\nIn Gratitude," +

"\n\n\n\n" + w1 + "\n" + w2 + "\nNA" + "\nCell: " + w3;

//

Please let m eknow if you would like a copy of my file and i can try and send it. 

This topic has been closed for replies.

1 reply

PDF Automation Station
Community Expert
Community Expert
September 16, 2024

Is the text in a form field?  If so, you have to set the field to allow Rich Text Formatting in the options tab and then create an object for all the different blocks of text.

CMunro87Author
Known Participant
September 16, 2024

Yes it is , the text populates in "Calc_Text".  I understand emabling RT Formating but im not quite following what you mean by "create an object for the text "

PDF Automation Station
Community Expert
Community Expert
September 17, 2024

Thank you for this! This will be useful for me with another project. However, instead of creating spans throughout, is there a way to simply just underline or italicize the text? Like for example:

 

// Custom Format script for text field
if (!event.value) {
event.value = "I would like to make this text italics";
} else {
event.target.display = display.visible;
}

 

I'm borrowing a previous answer posted elsewhere regarding creating disappearing instructional text fields and would like to go the additional step of italicizing it. Not the text that the user enters into the field, just the disappearing text. If possible, avoiding the Rich Text format requirement. 

 

Thanks!


Rich text formatting is the only way to do this.  Without the rich text option the entire contents of the field must be formatted the same way.  With rich text formatting selected, and text entered, you can select portions of the text and format them from the rich text formatting toolbar which will appear when you have text in the field selected and you press Ctrl + e.  This issue here is that you will lose the formatting when the user modifies the text in the field.

To use your example, you can manually set the field to Rich text formatting then enter the following custom format script:

if (!event.value) 
{
var spans = new Array();
spans[0] = new Object();
spans[0].text = "I would like to make this text ";

spans[1] = new Object();
spans[1].text = "italics";
spans[1].fontStyle="italic";
event.richValue=spans;
} 
else 
{event.target.display = display.visible;}