Skip to main content
Participating Frequently
August 27, 2020
Answered

Adding a string to beginning of field if field contains user input

  • August 27, 2020
  • 2 replies
  • 2526 views

Hi all,

I am new to Javascript, but have coded in VBA for a while...very different!

I am trying to figure out how to add a fixed string to the beginning of a field after the user inputs their data.

 

Any help would be awesome!

 

Thanks...

This topic has been closed for replies.
Correct answer try67

As the field's custom Format script enter this code:

if (event.value) event.value = "AWARDS: "+event.value;

2 replies

Legend
August 29, 2020

You may also want to take precautions to avoid ending up with a field containing AWARDS: AWARDS: AWARDS: ... if the user tries to correct their input. In general, changing what the user types is a bad idea because it conflicts with the user's normal editing.

try67
Community Expert
Community Expert
August 29, 2020

That won't happen if they use the script I provided under the Format event.

Legend
August 29, 2020

Indeed. Format good. Validate bad. onBlur bad. People do have a habit of using random events rather than finding out the right one... The "user is done" idea is also a dangerouus one. It's entirely normal to return several times to the same field. This is as bad as trying to force people to fill forms "in order".

try67
Community Expert
Community Expert
August 27, 2020

Do you want the string to be an actual part of the field's value, or just to be displayed? If the former, keep in mind that each time the user edits the field it will add the string again to the start of it, unless your script checks for that first.

Participating Frequently
August 27, 2020

Just realized whata you were asking...

I guess it doesn't really matter which way. Part of the field input or not, but I can see the advantages to it "Apprearing" at outside of the field if the field is not null.

If inside of the field, I was thinking something like a Concatenate. Just add "AWARDS:" & User string

IF outside of field (at lead) then only if field is not null or >""

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 27, 2020

As the field's custom Format script enter this code:

if (event.value) event.value = "AWARDS: "+event.value;