Multiple select validation
<p>I have a form in HTML, that has several select elements, what is the best way to make validation for them in such way that no two select elements can have same value, validation function should fire on select, so it can check are there any selects with the same option value if yes then alert something, can I get a explanation how to write this in javascript?</p>

<p>Thank you</p>

<p>here is a bit of HTML code I want to validate :</p>

<pre><code>    &lt;form name="forma" action="" method="POST"&gt;

    &lt;select name="sel1"&gt;
  &lt;option&gt;Please select&lt;/option&gt;
    &lt;option&gt;brand1&lt;/option&gt;
    &lt;option&gt;brand2&lt;/option&gt;
    &lt;option&gt;brand3&lt;/option&gt;
    &lt;/select&gt;

    &lt;select name="sel2"&gt;
   &lt;option&gt;Please select&lt;/option&gt;
    &lt;option&gt;brand1&lt;/option&gt;
    &lt;option&gt;brand2&lt;/option&gt;
    &lt;option&gt;brand3&lt;/option&gt;
    &lt;/select&gt;

    &lt;select name="sel3"&gt;
    &lt;option&gt;Please select&lt;/option&gt;
    &lt;option&gt;brand1&lt;/option&gt;
    &lt;option&gt;brand2&lt;/option&gt;
    &lt;option&gt;brand3&lt;/option&gt;
    &lt;/select&gt;

    &lt;/form&gt;
</code></pre>

<p>Here is the solution slightly adjusted but this is it:</p>

<pre><code>var selectTest = function () {
    var i, j;
    sels = [document.getElementById("sel1"), document.getElementById("sel2"), document.getElementById("sel3")];
    for (i = 0; i &lt; sels.length; i += 1) {
        for (j = i + 1; j &lt; sels.length; j += 1) {
     if(sels[i].value != "Please select")
         {
            if (sels[i].value === sels[j].value) {
                alert("Selected values must be different");
                return;
            }
      }
        }
    }

};
</code></pre>

<p>Special tnx to <a href="http://stackoverflow.com/users/159690/austin-cheney">austin cheney</a>, thanks to everyone who posted and participated.</p>
