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

Question

Question

how to trap for a selection in a collection

asked on August 8, 2016 Show version history

I have a collection on a form, and based on the selection of a Radio Button object Yes, I want to fill the values of the collection address with the other previous values entered on the form.  How would I call this object "q163"? 

0 0

Replies

replied on August 8, 2016

Hi Mary,

Try using this script. I just added the class 'my-address' to the date you want to copy, a class 'dependent-address-q' to the radio button, and a class 'dependent-address' to the dependent address field:

$(document).ready(function() {
  $("#q103 .dependent-address-q").change(function() {
    $('.dependent-address-q').each(function() {
		var selected = $('input', this).get(0);
    	if($(selected).is(":checked")) {    
          var address= $('.my-address input').val();
          $(this).next().find('input').val(address);
        } 
    });     
  });
});

 

1 0
replied on August 8, 2016

I'm not sure I follow.  It looks like your example is opposite of what I am trying to do.

Here is how I have identified the objects on my form:

  • collection class - .depform
  • radio button on collection class - .DepSameAddress
  • field on collection class - .DepAddr
  • field class - .EEAddr

 

Here is the series of events:

  1. user - the employee information is entered at the top (including address information)
  2. user - the dependent information is on the collection following
  3. user - click radio button on collection for the address from the employee to be copied over to the dependent
  4. jquery - on the click event, check if value is Yes
  5. jquery - replace the collection address with address from employee

 

 

0 0
replied on August 9, 2016

The script below provides an example of how to copy one of the inputs. All you have to do is extend the code in the if block to get the other inputs.

0 0
replied on August 9, 2016

Thanks for all you help.

Here is my code, it works only for the first time in the collection.  When the Add is clicked, the code does not work.  How do I make it work on each added sections in the collection?

$(document).ready(function() {

  $("#q103 .DepSameAddress").change(function() {
    $('.DepSameAddress').each(function() {
      if ($('input[value="Yes"]').is(':checked')){
        var address = $('.EEAddr input').val();
        var address2 = $('.EEAddr2 input').val();
        var city = $('.EECity input').val();
        var state = $('.EEState input').val();
        var zip = $('.EEZip input').val();
        $('.DepAddr').find('textarea').val(address);
        $('.DepAddr2').find('input').val(address2);
        $('.DepCity').find('input').val(city);
        $('.DepState').find('input').val(state);
        $('.DepZip').find('input').val(zip);
      }
    });
  });

});

0 0
replied on August 9, 2016

You need to use this king of format for the last 5 lines.

$(this).next().find('.DepAddr textarea').val(address);

 

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

Sign in to reply to this post.