Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Paste the following jQuery script into a custom HTML script within the form. This script will set the initial value of the 'value' field to the selected option in the dropdown box upon page load and selection, thus allowing dynamic interaction.

Note

Be Make sure to change the JQuery jQuery selector name to the respective IDs of the select box and text field ID ; otherwise, the script wouldnwon't work.

Figure 3: JQuery Script

Code Block
languagejs
<script>
$(document).ready(function() {
  //Set initial value with selected option
  $('input[name="value"]').val($('select[name="selector"]').val() + " ");
    
  $('select[name="selector"]').on('change', function() {
    // Get the selected value from selector
    if ($(this).val() === "USD" || $(this).val() === "POUND") {
        var selectedCurrency = " " + $(this).val();
    
        // Get the current value of currency_field
        var currentValue = $('input[name="value"]').val();
    
        // Set the updated value to currency_field by concatenating the selected currency
        $('input[name="value"]').val(currentValue + selectedCurrency);
    }
    else{
            var selectedCurrency = $(this).val()+ " ";
            
            // Set the updated value to currency_field
            $('input[name="value"]').val(selectedCurrency);
        }

  });
});

 </script>

...