Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a generalized solution.</p> <p>Construct your HTML as follows, ensuring that the text contained by the anchors ("Boy" / "Girl") exactly matches the values of the corresponding menu options.</p> <p>HTML:</p> <pre><code>&lt;tr class="box1"&gt; &lt;td&gt; &lt;select class="remoteSelectable" id="cimy_uef_7"&gt; &lt;option value="Boy"&gt;Boy&lt;/option&gt; &lt;option value="Girl"&gt;Girl&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;div id="genderBox1" class="remoteSelector" data-menu="cimy_uef_7"&gt; &lt;div class="gender"&gt;&lt;a href=""&gt;Boy&lt;/a&gt;&lt;/div&gt; &lt;div class="gender"&gt;&lt;a href=""&gt;Girl&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>javascript:</p> <pre><code>//force select menus to same value as clicked remote link $(".remoteSelector a").on('click', function(e) { e.preventDefault(); var $this = $(this).addClass('selected'), $container = $this.closest(".remoteSelector"); $container.find("a").not(this).removeClass('selected'); $('#' + $container.data('menu')).val($this.text()); }); //force remote links to reflect value of selected menu option $(".remoteSelectable").on('change', function() { var $this = $(this); $(".remoteSelector").filter(function() { return $(this).data('menu') == $this.attr('id'); }).find("a").removeClass('selected').filter(function() { return $(this).text() == $this.val(); }).addClass('selected'); }).trigger('change'); </code></pre> <p><strong><a href="http://jsfiddle.net/52Lr5/2/" rel="nofollow">DEMO</a></strong></p> <p>Notes :</p> <ul> <li><p>The 'change' handler is triggered immediately to force the correct remote link to be styled 'selected'.</p></li> <li><p>The select menus may be hidden by moving them off-screen with absolute positioning, or with <code>display:none</code> if they are not part of a form that's going to be submitted.</p></li> </ul> <p>If at any point (after the handlers are attached) the menus need to be changed programatically then do so as follows to ensure the corresponding remote link is kept up to date :</p> <pre><code>$("#cimy_uef_7").val('Girl').trigger('change'); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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