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

Question

Question

Fill in Multi Line text field When Drop-Down is Selected?

asked on October 9, 2015

I have a drop-down field on a form that lists different buildings. Further down on the same form I have a table that displays 3 rows by default and has 4 fields in each row. The first field in the row is a multi-line text field. I need to be able to populate specific text values in the multi-line text fields for the first 2 rows dependent on the options selected in the drop-down field mentioned earlier. A different value will need to be entered for each drop-down option. 

Does anyone know how to go about this? Thank you for your help in advance.

1 0

Answer

SELECTED ANSWER
replied on October 9, 2015 Show version history

Would something like this work for you? This example uses a drop down with hard coded choices and values.

JavaScript

$(document).ready(function () {
  $('.buildings select').on('change', function () {
    if ($(this).val() == "Empire State Building") {
      $('[name="Field2(1)"]').val("Some Text for ESB, Row 1");
      $('[name="Field2(2)"]').val("Some Text for ESB, Row 2");
    } else if ($(this).val() == "White House") {
      $('[name="Field2(1)"]').val("Some Text for WH, Row 1");
      $('[name="Field2(2)"]').val("Some Text for WH, Row 2");
    } else if ($(this).val() == "Petronas Towers") {
      $('[name="Field2(1)"]').val("Some Text for PT, Row 1");
      $('[name="Field2(2)"]').val("Some Text for PT, Row 2");
    } else if ($(this).val() == "Taj Mahal") {
      $('[name="Field2(1)"]').val("Some Text for TM, Row 1");
      $('[name="Field2(2)"]').val("Some Text for TM, Row 2");
    } else if ($(this).val() == "Sydney Opera House") {
      $('[name="Field2(1)"]').val("Some Text for SOH, Row 1");
      $('[name="Field2(2)"]').val("Some Text for SOH, Row 2");
    } else if ($(this).val() == "") {
      $('[name="Field2(1)"]').val("");
      $('[name="Field2(2)"]').val("");
    }
  });
});

It checks for when the drop down changes and then based on the selected option, it will set specific text into the first column in the first two rows of the table.

1 0
replied on October 9, 2015

That is beautiful! Thank you.

1 0

Replies

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

Sign in to reply to this post.