0

Case:

I'm building a form using Formidable Pro and I want to copy the value of one field to another using this code:

<script>    
jQuery(document).ready(function($){
    $('#field_ttvo4').change(function(){ 
        var sourceField = $('#field_ttvo4').val();
        $('#field_4f0kv').val(sourceField);
        $('#field_4f0kv').trigger({ type:'change', originalEvent:'custom' });
    });
});
</script>

Problem:

This field looking up a value from the previous page of the form and it doesn't get copied in field_4f0kv. I have to remove the last digit, re-type it and leave ttvo4 before 4f0kv gets populated. Supposedly I'm using the wrong trigger but I can't figure out how to copy the field without altering ttvo4.

Vickel
  • 7,879
  • 6
  • 35
  • 56
  • Use `.on("input", function () {` instead of `.change(function () {` –  Dec 27 '19 at 12:56

1 Answers1

1

If you want your value to copy over as you type, you should be using either the input or keyup events, though input is probably better

jQuery(document).ready(function($) {
  $('#field_ttvo4').on('input', function() {
    $('#field_4f0kv').val($(this).val());
    $('#field_4f0kv').trigger({type: 'input', originalEvent: 'custom'});
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<input id="field_ttvo4" />
<input id="field_4f0kv" />
Shiny
  • 4,945
  • 3
  • 17
  • 33