Select all checkboxes - but only ones with the same table cell value
<p>Hopefully I can explain this without overcomplicating the issue, so please bear with me. I already know how to write some JavaScript to select all check boxes within a form, but how would you go about doing the following?</p>

<p>Here is the code:</p>

<pre><code>&lt;tr&gt;
    &lt;td&gt;
        &lt;input type="checkbox" name="array[]" value="value1"/&gt;
    &lt;/td&gt;
    &lt;td&gt;
        Some Field
    &lt;/td&gt;
    &lt;td&gt;
        Bob
    &lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td&gt;
        &lt;input type="checkbox" name="array[]" value="value2"/&gt;
    &lt;/td&gt;
    &lt;td&gt;
        Some Field
    &lt;/td&gt;
    &lt;td&gt;
        Bob
    &lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td&gt;
        &lt;input type="checkbox" name="array[]" value="value3"/&gt;
    &lt;/td&gt;
    &lt;td&gt;
        Some Field
    &lt;/td&gt;
    &lt;td&gt;
        Fred
    &lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td&gt;
        &lt;input type="checkbox" name="array[]" value="value4"/&gt;
    &lt;/td&gt;
    &lt;td&gt;
        Some Field
    &lt;/td&gt;
    &lt;td&gt;
        Jack
    &lt;/td&gt;
&lt;/tr&gt;
</code></pre>

<p>I want to be able to select/unselect all the checkboxes relevant to "Bob", but not Jack or Fred. The common data must be contained within a TD element. Is this even possible?</p>

<p>If someone could help that would be fantastic!</p>

<p>Many thanks for your reply subhaze but I'm not having much luck getting it to work, here is my code now:</p>

<pre><code>function selectBOB() {
    var trs = document.getElementsByTagName('tr');
    for( var i = 0; i &lt; trs.length; i++ ) {
        var tds = trs[i].getElementsByTagName('td');
        for( var k = 0; k &lt; tds.length; k++ ) {
            if( tds[k].innerText == 'Bob' ) {
                trs[i].getElementsByTagName('input')[0].checked = 'checked'; 
            }  
        }
    }
}

&lt;input type="checkbox" name="sAll" onclick="selectBOB(this)" /&gt; Select Bob
</code></pre>
