Auto Populate Reference field based on another Reference field

Austine
Tera Contributor

How can I auto populate a field value based on the value selected on another field? Basically, these are two different fields that are referencing the same table, so we want the value selected for field 1 to be auto populated in field 2.

 

Thanks.

 

8 REPLIES 8

Sandeep Rajput
Tera Patron
Tera Patron

@Austine You can create an onChange client script on field 1 and set the value of field 2 inside it. Here is an example

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
g_form.setValue('field_2',newValue); //Set the value of second field here

}

Hope this helps.

Hi @Sandeep Rajput,

 

Thank you for response. I have just tried it, but didn't work please.

@Austine Could you please share the names of these fields and why would you like to copy data of one field to another.

    • @Sandeep Rajput, The field names are Select Location and Site. Once again, they are both referencing the same table. So, whatever users select in the SELECT LOCATION field should auto populate in SITE field.

     

    Note: Site is a read-only field.

     

    Thank you.