Skip to main content
Henry.Ong
Inspiring
December 21, 2018
Answered

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

  • December 21, 2018
  • 5 replies
  • 7486 views

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.

This topic has been closed for replies.
Correct answer try67

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

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

5 replies

inspirien
Participating Frequently
June 1, 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.

try67
Community Expert
Community Expert
June 1, 2021

Change this:

if (textField="-")

To:

if (/-/.test(textField))

And use it as the custom calculation script.

inspirien
Participating Frequently
June 2, 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

Inspiring
November 2, 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;

try67
Community Expert
Community Expert
November 2, 2020

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

Inspiring
November 2, 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.

Henry.Ong
Henry.OngAuthor
Inspiring
February 20, 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

Henry.Ong
Henry.OngAuthor
Inspiring
February 20, 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

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
December 21, 2018

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

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

Henry.Ong
Henry.OngAuthor
Inspiring
December 22, 2018

Thanks! It works.