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

Is it possible to append a text to an input field?

Contributor ,
Dec 21, 2018 Dec 21, 2018

Copy link to clipboard

Copied

I would like to know if it is possible to append a text to an input field.

Example:

I have an input field, say "Weight"

What I would like to happen is when the user input 170, the field will display "170 lbs.". The "lbs." is appended to the value that is inputted in the field.

TOPICS
PDF forms

Views

4.9K

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Dec 21, 2018 Dec 21, 2018

Sure, that's possible. Use this code as the field's custom Format script:

if (event.value) event.value += " lbs.";

Votes

Translate

Translate
Community Expert ,
Dec 21, 2018 Dec 21, 2018

Copy link to clipboard

Copied

Sure, that's possible. Use this code as the field's custom Format script:

if (event.value) event.value += " lbs.";

Votes

Translate

Translate

Report

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
Contributor ,
Dec 21, 2018 Dec 21, 2018

Copy link to clipboard

Copied

Thanks! It works.

Votes

Translate

Translate

Report

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
Contributor ,
Feb 19, 2019 Feb 19, 2019

Copy link to clipboard

Copied

I tried this solution and first time I input a value, the text "lbs." is appended to my input.

However, when I go and enter value in another field, another "lbs." is appended so it now looks like "34 lbs. lbs.". The "lbs." keep on appending every time I enter values in other fields.

This happened only when you first enter value to this field and proceed entering values to other fields in the same form. But if its the last field your fill-out, it ok.

Please help me out here.

Thanks

Votes

Translate

Translate

Report

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
Contributor ,
Feb 19, 2019 Feb 19, 2019

Copy link to clipboard

Copied

Please ignore this posting. I was able to realized my error. I should have put the script in Validate > Run Custom Validation Script. Sorry

Votes

Translate

Translate

Report

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
Explorer ,
Nov 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

I'm trying to do something similar, but in reverse order.  How do I modify the script example above to insert "Thank you for your submission, " + field name ("Your Name")?

 

My current script is: event.value = this.getField("Your Name").valueAsString;

Votes

Translate

Translate

Report

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 ,
Nov 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

event.value = "Thank you for your submission, " + this.getField("Your Name").valueAsString;

Votes

Translate

Translate

Report

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
Explorer ,
Nov 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

Thank you for the reply.  However the text "Thank you for your submission, " automatically displays when the form opens and before the user enters their name.  I want that text string to populate, along with the user's entry of their name to come up after the user enters his/her name.

Votes

Translate

Translate

Report

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 ,
Nov 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

Use this:

 

var name = this.getField("Your Name").valueAsString;
if (name=="") event.value = "";
else event.value = "Thank you for your submission, " + name;

Votes

Translate

Translate

Report

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
Explorer ,
Nov 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

Thank you. Works perfectly.

Votes

Translate

Translate

Report

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 ,
Jun 01, 2021 Jun 01, 2021

Copy link to clipboard

Copied

Can someone help me with my issue that is similar?  If the text includes a "-" (negative sign) then just use the value of that field, otherwise, add a "+" before the field value. 

 

var textField = this.getField("This.#PropCov.CustomNumber38").valueAsString;

 

if (textField="-") event.value = this.getField("This.#PropCov.CustomNumber38").valueAsString;
else event.value = "+" + this.getField("This.#PropCov.CustomNumber38").valueAsString

 

Also - I have been adding this to my "Format", "Validate" and "Calculate" fields - but I do not think that is correct.

Votes

Translate

Translate

Report

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 ,
Jun 01, 2021 Jun 01, 2021

Copy link to clipboard

Copied

Change this:

if (textField="-")

To:

if (/-/.test(textField))

And use it as the custom calculation script.

Votes

Translate

Translate

Report

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 ,
Jun 01, 2021 Jun 01, 2021

Copy link to clipboard

Copied

I tried that and still didn't work.

 

var textField = this.getField("This.#PropCov.CustomNumber38").valueAsString;

if (/-/.test(textField)) event.value = this.getField("This.#PropCov.CustomNumber38").valueAsString;
else event.value = "+" + this.getField("This.#PropCov.CustomNumber38").valueAsString

Votes

Translate

Translate

Report

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 ,
Jun 02, 2021 Jun 02, 2021

Copy link to clipboard

Copied

Where does you use the script?

Votes

Translate

Translate

Report

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 ,
Jun 02, 2021 Jun 02, 2021

Copy link to clipboard

Copied

I put the script in the PDF -> Text Field Properties -> Calculate Tab -> Custom Calculation Script 

Votes

Translate

Translate

Report

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 ,
Jun 02, 2021 Jun 02, 2021

Copy link to clipboard

Copied

At what field?

Votes

Translate

Translate

Report

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 ,
Jun 02, 2021 Jun 02, 2021

Copy link to clipboard

Copied

Field Name: This.#PropCov.CustomNumber38

Votes

Translate

Translate

Report

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 ,
Jun 02, 2021 Jun 02, 2021

Copy link to clipboard

Copied

Replace
this.getField("This.#PropCov.CustomNumber38").valueAsString
with
event.value

Votes

Translate

Translate

Report

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 ,
Jun 02, 2021 Jun 02, 2021

Copy link to clipboard

Copied

Like this?

var textField = this.getField("This.#PropCov.CustomNumber38").valueAsString

if (textField=="-") event.value = this.getField("This.#PropCov.CustomNumber38").valueAsString;
else event.value = "+" + event.value;

 

What I am expecting is IF the value has a Negative (-) sign like this -1443, THEN it will just be 1443. IF it doesn't have a Negative sign then it will add a Plys (+) sign to the value instead. 

Votes

Translate

Translate

Report

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 ,
Jun 02, 2021 Jun 02, 2021

Copy link to clipboard

Copied

Why have you replaced only one entry?

Votes

Translate

Translate

Report

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 ,
Jun 02, 2021 Jun 02, 2021

Copy link to clipboard

Copied

Replaced all and now this is how it looks:

 

var textField = event.value

if (textField=="-") event.value = "+" + event.value
else event.value = "-" + event.value;

 

I guess I am still doing something wrong, still not working.

Votes

Translate

Translate

Report

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 ,
Jun 02, 2021 Jun 02, 2021

Copy link to clipboard

Copied

Enter a minus sign and you will get +-

 

Votes

Translate

Translate

Report

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 ,
Jun 02, 2021 Jun 02, 2021

Copy link to clipboard

Copied

LATEST

This line of code:

if (textField=="-")

Means "if textField equals '=' EXACTLY".

It will return false if the value of textField is "-1446", for example.

That's why I fixed it for you in my original reply, which would solve this problem.

Votes

Translate

Translate

Report

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 ,
Jun 01, 2021 Jun 01, 2021

Copy link to clipboard

Copied

To compare use double ==

if(textField =="-"... 

Votes

Translate

Translate

Report

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 ,
Jun 01, 2021 Jun 01, 2021

Copy link to clipboard

Copied

I tried that as well and it still didn't work. 

Votes

Translate

Translate

Report

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