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

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

Contributor ,
Dec 21, 2018 Dec 21, 2018

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
6.7K
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 ,
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.";

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
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.";

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

Thanks! It works.

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

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

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

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

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

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;

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

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

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

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.

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

Use this:

 

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

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
Explorer ,
Nov 02, 2020 Nov 02, 2020
Thank you. Works perfectly.
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 ,
Jun 01, 2021 Jun 01, 2021

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.

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

Change this:

if (textField="-")

To:

if (/-/.test(textField))

And use it as the custom calculation script.

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

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

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

Where does you use the script?

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

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

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

At what field?

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

Field Name: This.#PropCov.CustomNumber38

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

Replace
this.getField("This.#PropCov.CustomNumber38").valueAsString
with
event.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
New Here ,
Jun 02, 2021 Jun 02, 2021

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. 

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

Why have you replaced only one entry?

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

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.

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

Enter a minus sign and you will get +-

 

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

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

To compare use double ==

if(textField =="-"... 

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

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

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