Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Don't know if I understood what you're trying to do, but maybe the following code will help.</p> <p><a href="http://jsfiddle.net/cfQSr/19/" rel="nofollow">http://jsfiddle.net/cfQSr/19/</a></p> <p>It adds the class <code>mismatch</code> to <code>td</code>s whose <code>input</code>s don't match, if the corresponding <code>select</code> have the same value:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;js&lt;/title&gt; &lt;script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"&gt;&lt;/script&gt; &lt;style type="text/css"&gt; .mismatch { background: #ff9999; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;form name="form1" ID="form1" action="array_script.cfm"&gt; &lt;table id="test1"&gt; &lt;tr&gt; &lt;td&gt; &lt;select name="selectA" id="selectA" class="priceA"&gt; &lt;option id="A" value=""&gt;None&lt;/option&gt; &lt;option id="A" value="A"&gt;A&lt;/option&gt; &lt;option id="A" value="B"&gt;B&lt;/option&gt; &lt;option id="A" value="C"&gt;C&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;td&gt; &lt;input id="priceA" type="text" name="price" value="8.99"&gt; &lt;/td&gt; &lt;td&gt; &lt;input id="perCaseA" type="text" name="perCase" value="4"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;select name="selectB" id="selectB" class="priceB"&gt; &lt;option id="B" value=""&gt;None&lt;/option&gt; &lt;option id="B" value="A"&gt;A&lt;/option&gt; &lt;option id="B" value="B"&gt;B&lt;/option&gt; &lt;option id="B" value="C"&gt;C&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;td&gt; &lt;input id="priceB" type="text" name="price" value="8.99"&gt; &lt;/td&gt; &lt;td&gt; &lt;input id="perCaseB" type="text" name="perCase" value="4"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;select name="selectC" id="selectC" class="priceC"&gt; &lt;option id="C" value=""&gt;None&lt;/option&gt; &lt;option id="C" value="A"&gt;A&lt;/option&gt; &lt;option id="C" value="B"&gt;B&lt;/option&gt; &lt;option id="C" value="C"&gt;C&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;td&gt; &lt;input id="priceC" type="text" name="price" value="8.99"&gt; &lt;/td&gt; &lt;td&gt; &lt;input id="perCaseC" type="text" name="perCase" value="4"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;script type="text/javascript"&gt; (function () { "use strict"; $('#form1').bind('change', function (evt) { $('td.mismatch', this).removeClass('mismatch'); var selects = $('select', this); $(selects).each(function () { var that = this; $(selects).not(this).each(function () { // we have a similar select if ($(this).val() !== '' &amp;&amp; $(this).val() === $(that).val()) { // now compare inputs var thisInputs = $('input', $(this).closest('tr')), thatInputs = $('input', $(that).closest('tr')); $(thisInputs).each(function (i) { if ($(this).val() !== $(thatInputs).eq(i).val()) { $(this).closest('td').addClass('mismatch'); $(thatInputs).eq(i).closest('td').addClass('mismatch'); } }); } }); }); }); }()); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </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. 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