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

Question

Question

How to populate Mailing address if checkbox checked

asked on August 20, 2020

Has anyone written any code to populate the mailing address from the physical address if a checkbox is checked in Form?

0 0

Answer

SELECTED ANSWER
replied on August 20, 2020 Show version history
  1. Create two address fields.
  2. Give the address fields the CSS classes "addressOne" and "addressTwo" respectively.
  3. Create a checkbox.
  4. Change the Choices of the checkbox to "Yes"
  5. Give the checkbox the CSS class "addressCheck".
  6. Enter the following JavaScript:
    $(document).ready(function(){
      $('.addressCheck').change(function () {    
    
      var firstAddress = $('.addressOne').find('input');
      var secondAddress = $('.addressTwo').find('input');
        
        if ($(this).find('input[value="Yes"]').is(':checked')){
    
        for (i = 0; i < 6; i++) {
    
          $(secondAddress[i]).val($(firstAddress[i]).val());
    
        }
    
        } else {
    
         secondAddress.val('');
    
        }
        
      }); 
    }); 

 

From a usability point of view, it may be better to use a button for this operation.

You can add a button using Custom HTML.

In the HTML tab of Custom HTML, add the following:

<input id="copyAddressButton" type="button" value="Use the same address">

Then in JavaScript use the following:

$(document).ready(function(){
  $("#copyAddressButton").click(function(){
    
    var firstAddress = $('.addressOne').find('input');
    var secondAddress = $('.addressTwo').find('input');
    
    for (i = 0; i < 6; i++) {

      $(secondAddress[i]).val($(firstAddress[i]).val());

    }
    
  });
}); 

 

1 0

Replies

replied on August 20, 2020

Awesome!  I will give this a try.

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

Sign in to reply to this post.