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

Question

Question

Dynamically merge the content of 2 fields onto 1 field

asked on April 12, 2017

Hi,

The image below is my form:

How can I make the content of "SingleLine" and "SingleLine2" merge and appear in "Result" as soon as both fields contain something?

Regards,

1 0

Answer

SELECTED ANSWER
replied on April 12, 2017 Show version history

You can do this without using custom JavaScript by using the =CONCATENATE() function in the calculation in Result.  This will combine even if one of the fields are empty, but you could resolve that by making both single line fields required.

 

 

 

Edit - you can combine multiple variables by separating them with commas.  =CONCATENATE(Val1, Val2, Val3)

2 0

Replies

replied on April 12, 2017

Here's sample JS

$(document).ready(function () {
  $('.hasvalue input').on('change', function () {
    if ($('#Field1').val() !== '' && $('#Field2').val() !== '') {
      $('.result input').val($('#Field1').val() + " - " + $('#Field2').val());
    } else {
      $('.result input').val('');
    }
  });
});

Give the two "single line" fields a CSS class like hasvalue. Then give the "result" field a CSS class like result. The above checks for changes in the fields with the hasvalue class and if both fields are not empty, then combine the values and set it into the result field. Otherwise, leave the result field blank.

4 0
replied on April 13, 2017

Thank you Eric and Alex. I have tried the non-javascript method and it worked perfectly

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

Sign in to reply to this post.