Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try this :</p> <pre><code>$('select[name="color_list"]').change(function() { $('input[color=' + $(this).val() + ']').prop('checked',true); }); </code></pre> <p>This is using <a href="http://api.jquery.com/prop/" rel="nofollow">.prop()</a> to set the radio button as checked, and <a href="http://api.jquery.com/val/" rel="nofollow">.val()</a> to get the value from the selected <code>option</code></p> <p>or using <code>prop('name')</code> instead of <code>val()</code> on the <code>option</code></p> <p><code>$('input[color=' + $(this).prop('name') + ']').prop('checked',true);</code></p> <p>or if using jQuery &lt; 1.6 - you cannot use <code>prop</code>, you have to use <a href="http://api.jquery.com/attr/" rel="nofollow">.attr()</a></p> <p><code>$('input[color=' + $(this).val() + ']').attr('checked','checked');</code></p> <p><a href="http://jsfiddle.net/gu5Ug/" rel="nofollow">Working example here</a></p> <p>Looking at your site - the problem is clear :</p> <pre><code>$('select[name="color_list"]').change(function() { $('.color').removeClass('selected'); $('.color').addClass('selected'); $('input[color=' + $(this).attr('color') + ']').prop('checked',true); }); </code></pre> <p>your adding the <code>selected</code> class to every swatch, change it to this :</p> <pre><code>$('select[name="color_list"]').change(function() { $('.color').removeClass('selected'); $('div[color=' + $(this).attr('color') + ']').addClass('selected'); $('input[color=' + $(this).attr('color') + ']').prop('checked',true); }); </code></pre> <p>this only adds the class to the correct swatch. (note you might have to lowercase the value from the option)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload