I have two sets of radio buttons, each with four options.
The first set has no default selection (unchecked) using jQuery, while the second set has the first option checked by default.
What I'm looking to achieve is that when a radio button in the first set is checked, it should automatically check the corresponding one in the second set.
Here's the HTML structure:
<p class="form-row form-row-wide validate-required" id="billing_piegadatajs_field"><label for="billing_piegadatajs" class="">Delivery Method <abbr class="required" title="required">*</abbr></label><br>
<input type="radio" name="billing_piegadatajs" value="Post Office" class="radio" style="width:10%" checked="checked"><span for="billing_piegadatajs">Post Office</span><br>
<input type="radio" name="billing_piegadatajs" value="Post24" class="radio" style="width:10%"><span for="billing_piegadatajs">Post 24</span><br>
<input type="radio" name="billing_piegadatajs" value="Courier Service" class="radio" style="width:10%"><span for="billing_piegadatajs">Courier Service</span><br>
<input type="radio" name="billing_piegadatajs" value="Pickup" class="radio" style="width:10%"><span for="billing_piegadatajs">Pickup (Location: Saldū)</span>
</p>
<br>
<tr class="shipping">
<th>Shipping Costs</th>
<td>
<ul id="shipping_method">
<li>
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_flat_rate" value="flat_rate" checked="checked" class="shipping_method">
<label for="shipping_method_0_flat_rate">Post Office: <span class="amount">€ 3.50</span></label>
</li>
<li>
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_international_delivery" value="international_delivery" class="shipping_method">
<label for="shipping_method_0_international_delivery">Post 24: <span class="amount">€ 3.50</span></label>
</li>
<li>
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_apg_shipping" value="apg_shipping" class="shipping_method">
<label for="shipping_method_0_apg_shipping">DLW Courier: <span class="amount">€ 9.00</span></label>
</li>
<li>
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_local_pickup" value="local_pickup" class="shipping_method">
<label for="shipping_method_0_local_pickup">On-site Pickup - Saldū (Free)</label>
</li>
</ul>
</td>
</tr>
I am using this jQuery script to uncheck the radio buttons in the first set when the page loads:
jQuery(document).ready(function(){
jQuery('#billing_piegadatajs_field')
jQuery('#billing_piegadatajs_field').find('input[name="billing_piegadatajs"]').each(function() {
jQuery(this).prop('checked', false);
});
});
Here is a link to jsfiddle