Autofill form with existing form values

461 views Asked by At

I am trying to get a form field to autofill with the same value as another field using Ninja Forms and Wordpress. I have looked at some solutions using JQuery but none of them seem to work. Please help me figure out what I am doing wrong.

Here is a link to the form: https://optionsqa.wpengine.com/test-page/

I want to get the content in "COPY THIS LINK" to automatically populate the field below.

This is the script I am trying:

<script type="text/javascript">

jQuery(document).ready(function() {
 jQuery('.copy-link').on('change', function() {
   jQuery('.favorite-link-field').val($(this).val());
 }); 
});

</script>

1

There are 1 answers

4
Mech On

jQuery solution (updated to include ninja form ready state, as per comments):

I prefer using the id over class since classes can be used multiple times. That being said:

This will update when #nf-field-10 or Favorites Link is changed.

jQuery(document).on( 'nfFormReady', function( e, layoutView ) {
 jQuery('#nf-field-10').on('change', function() {
   jQuery('#nf-field-10').val(jQuery('#nf-field-16').val());
 }); 
});