You are viewing limited content. For full access, please sign in.

Question

Question

How to add a value to a field in forms through javascript

asked on September 20, 2022

I am trying to add a value infront of a lookup value that is populated in a field. For example, through a database lookup, a field is autopopulated. However, I want to add a default value infornt of this lookup value. Is there a way to do this through Javascript? Thanks 

0 0

Replies

replied on September 20, 2022

If the value you are trying to add is also among the lookup return value, you can just add the value as the dropdown's choice and set it as default value from the field settings. 

1 0
replied on September 21, 2022

Hi Xiuhong, the value I am trying to add is not part of the lookup return value. For example, when the return value is populated, (ex. Tom), I would want to add a value before this (Ex. Principal). The final result would be "Principal Tom". Is there a way to achieve this? Thanks for your help 

0 0
replied on September 21, 2022 Show version history

One option would be to add another field with a formula on it, kinda like this:

=IF(name_from_lookup="", "", "Principal " & name_from_lookup)

This looks at the field with variable "name_from_lookup".  If that field is blank, this field will also be blank.  But if that field has a value, this field will be populated with "Principal " and the  value from the other field.  So when name_from_lookup=Tom, then this field will be Principal Tom.

The actual name_from_lookup field could be hidden from view as well, and then you'd just see the field showing Principal Tom.

Will something like that work for you?

0 0
replied on September 21, 2022

Your easiest way to do this would be to create a SQL view and add the prefix in the view and forms does not need to do any of the work.  Otherwise, you would have to push the lookup value into a hidden field and use either a formula or Javascript to prepend your added text and push the new value to the user visible field.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.