Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I like to use a <code>rel="[id]"</code> on the element meant to reference another on some action:</p> <pre><code>&lt;input type="checkbox" class="options" name="option1" id="option1" rel="textbox1"&gt; &lt;input type="text" id="textbox1" class="textbox" value="test 1"&gt;&lt;br /&gt; &lt;input type="checkbox" class="options" name="option2" id="option2" rel="textbox2"&gt; &lt;input type="text" id="textbox2" class="textbox" value="test 2"&gt;&lt;br /&gt; &lt;input type="checkbox" class="options" name="option3" id="option3" rel="textbox3"&gt; &lt;input type="text" id="textbox3" class="textbox" value="test 3"&gt;&lt;br /&gt; $('.options').click(function(){ console.log($('#'+$(this).attr('rel')).val()); }); </code></pre> <p><a href="http://jsfiddle.net/BZXTr/" rel="nofollow">http://jsfiddle.net/BZXTr/</a></p> <p>Using the <code>rel</code> on the clicked element, you can then add a class for instance so that you can find the <code>.include</code> element values:</p> <pre><code>&lt;input type="checkbox" class="options" name="option1" id="option1" rel="textbox1"&gt; &lt;input type="text" id="textbox1" class="textbox" value="test 1"&gt;&lt;br /&gt; &lt;input type="checkbox" class="options" name="option2" id="option2" rel="textbox2"&gt; &lt;input type="text" id="textbox2" class="textbox" value="test 2"&gt;&lt;br /&gt; &lt;input type="checkbox" class="options" name="option3" id="option3" rel="textbox3"&gt; &lt;input type="text" id="textbox3" class="textbox" value="test 3"&gt;&lt;br /&gt; &lt;input type="button" id="show" value="Show all checked values"/&gt; $('.options').click(function(){ $('#'+$(this).attr('rel')).toggleClass('include'); }); $('#show').click(function(){ var values = []; $('input.include').each(function(){ values.push(this.value); }); console.log(values); }); </code></pre> <p><a href="http://jsfiddle.net/BZXTr/1/" rel="nofollow">http://jsfiddle.net/BZXTr/1/</a></p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. 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