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"?
Question
Question
how to trap for a selection in a collection
Replies
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); } }); }); });
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:
- user - the employee information is entered at the top (including address information)
- user - the dependent information is on the collection following
- user - click radio button on collection for the address from the employee to be copied over to the dependent
- jquery - on the click event, check if value is Yes
- jquery - replace the collection address with address from employee
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.
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);
}
});
});
});
You need to use this king of format for the last 5 lines.
$(this).next().find('.DepAddr textarea').val(address);