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

The idea is that if a user inputs data into a field, it will add the string "AWARDS:" to the beginning of what they type. If the field is null, then it wont.

I was thinking of using BLUR for the validation since I don't want the action to take place until after the user is done.

 

I actually thought this would be simple, but in JAva, not so much! Still trying to figure this language out...