javascript - how to set checked radio button by checking another radio button -
i have 2 seperate fields 4 radio buttons each.
field nr1 has radio button unchecked using jquery, field nr2 has first radio button checked default.
what need is, if in field nr1 radio button checked, checks same radio button in field nr2.
here how html looks like:
<p class="form-row form-row-wide validate-required" id="billing_piegadatajs_field"><label for="billing_piegadatajs" class="">piegādes veids <abbr class="required" title="vajadzīgs">*</abbr></label><br> <input type="radio" name="billing_piegadatajs" value="pasta stacija" class="radio" style="width:10%" checked="checked"><span for="billing_piegadatajs">pasta stacija</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="kurjerdienests" class="radio" style="width:10%"><span for="billing_piegadatajs">kurjerdienests</span><br> <input type="radio" name="billing_piegadatajs" value="saņemt uz vietas" class="radio" style="width:10%"><span for="billing_piegadatajs">saņemt uz vietas ( saldū )</span> </p> <br> <tr class="shipping"> <th>piegādes izmaksas</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">pasta stacijas: <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 kurjeris: <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">uz vietas - saldū (bez maksas)</label> </li> </ul> </td> </tr> i use jquery uncheck field nr1 radio button when page loaded.
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 link jsfiddle
you can acheive in many many ways
one approach should considering 2 set of radio
you have 2 sets :
the first 1 share class name 'radio'
the second 1 share class name 'shipping_method'
the logic
1) add click event on radio of first set
2) order rank of 1 click on
3) force click event on radio button having same index in second set
// track click on first set of radio jquery('.radio').on('click',function(){ // element index , 1 click on var indx = jquery(this).index('.radio'); // trigger click on same index in second radio set jquery('.shipping_method')[indx].click(); }) there jsfiddle : http://jsfiddle.net/mmjrk/21/
Comments
Post a Comment