Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript help for Strikethrough using custom format

New Here ,
Sep 15, 2021 Sep 15, 2021

Hi,

 

 

I wanted to create a text field that will automatically add a strikethrough to whatever text is typed in. I currently have a custom format script set as:

 

event.value = "$"+event.value

 

,which allows a dollar sign to be placed at the beginning of whatever the user is typing, but I couldn't figure out how to automatically add a strikethrough. If someone can help with this simple inquiry, it'd be much appreciated!

TOPICS
JavaScript , PDF forms
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Sep 15, 2021 Sep 15, 2021

In text field properties under options tab, tick 'Allow rich text formatting' and use this code:
If you want to strikethrough dollar sign:

var str = event.value;
if(event.value){
var spans = new Array();
spans[0] = new Object();
spans[0].text = "$"+str;
spans[0].strikethrough = true;
event.richValue = spans;}

 

If you don't want to strikethrough dollar sign:

var str = event.value;
if(event.value){
var spans = new Array();
spans[0] = new Object();
spans[0].text = "$";

spans[1] = new Object();
spans[1].text = str;
spans[1].strikethrough = true;
event.richValue = spans;}

 

If you want space after dollar sign replace "$" with "$ ".

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 15, 2021 Sep 15, 2021

Do you want to strikethrough dollar sign also or just typed value?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 15, 2021 Sep 15, 2021

In text field properties under options tab, tick 'Allow rich text formatting' and use this code:
If you want to strikethrough dollar sign:

var str = event.value;
if(event.value){
var spans = new Array();
spans[0] = new Object();
spans[0].text = "$"+str;
spans[0].strikethrough = true;
event.richValue = spans;}

 

If you don't want to strikethrough dollar sign:

var str = event.value;
if(event.value){
var spans = new Array();
spans[0] = new Object();
spans[0].text = "$";

spans[1] = new Object();
spans[1].text = str;
spans[1].strikethrough = true;
event.richValue = spans;}

 

If you want space after dollar sign replace "$" with "$ ".

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 15, 2021 Sep 15, 2021
LATEST

Thank you, that worked exactly as I hoped. Just one more thing - is there a way to make the strikethrough line thicker? -

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines