Dynamic Dropdown Box validation
<p>I need a JavaScript Validation for Dynamic Drop Down Box when clicking the submit button. But the drop down box attribute name and id should be same for all drop down boxes. I tried below code but its not succeeded, its work well when there are multiple drop down box but its does not work when there is only one drop down box. Please help me for find out this problem or give me any suggestion without changing of attribute name and id of drop down box.</p>

<pre><code>&lt;script type="text/javascript"&gt;
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}
function payNow()
    {

    var freeColor = document.checkout.free_prod_color;
    var colorCount = 0;
    var sizeCount = 0;
    for(var j=0;j&lt;document.checkout.free_prod_color.length;j++) {
    if(freeColor[j].value.trim()=="")  {
        colorCount++;
    }
    }
    if(colorCount&gt;=1) {
        alert("Please select color for FREE product");
        return false;
    }
    }
  &lt;/script&gt;
  &lt;form name="checkout" action="checkout.jsp" method="post"&gt;
  &lt;table&gt;
  &lt;tr class="free" title="Free Product"&gt;
  &lt;td height="30" valign="top" class="list_cell"&gt;Max Shirt&lt;input type="hidden" name="free_prod_name" value="Max Shirt" /&gt;&lt;/td&gt;

  &lt;td valign="top" class="list_cell"&gt;
  &lt;select name="free_prod_color" id="free_prod_color"&gt;
  &lt;option value=""&gt;Select Color&lt;/option&gt;
  &lt;option value="73"&gt;2Tone Blue&lt;/option&gt;&lt;option value="74"&gt;Army Green&lt;/option&gt;&lt;option value="75"&gt;Asparagus&lt;/option&gt;&lt;option value="77"&gt;Bengal Tiger&lt;/option&gt;&lt;option value="78"&gt;Black&lt;/option&gt;&lt;option value="79"&gt;Black Pink&lt;/option&gt;&lt;option value="80"&gt;Blue Gray&lt;/option&gt;&lt;option value="81"&gt;Blue Leopard&lt;/option&gt;&lt;option value="82"&gt;Camou&lt;/option&gt;&lt;option value="83"&gt;Camou 2&lt;/option&gt;&lt;option value="84"&gt;Camou Blue&lt;/option&gt;&lt;option value="85"&gt;Camou Green&lt;/option&gt;&lt;option value="86"&gt;Charcoal&lt;/option&gt;&lt;option value="87"&gt;Dreamy Blue&lt;/option&gt;&lt;option value="88"&gt;Flaming Heart&lt;/option&gt;&lt;option value="89"&gt;Florence&lt;/option&gt;&lt;option value="90"&gt;Gray&lt;/option&gt;&lt;option value="91"&gt;Hunter Green&lt;/option&gt;&lt;option value="97"&gt;Jade&lt;/option&gt;&lt;option value="92"&gt;Leopard&lt;/option&gt;&lt;option value="93"&gt;Mosaic&lt;/option&gt;&lt;option value="94"&gt;Myrtle&lt;/option&gt;&lt;option value="95"&gt;Olive&lt;/option&gt;&lt;option value="96"&gt;Olive Dew&lt;/option&gt;&lt;option value="98"&gt;Purple Pink&lt;/option&gt;&lt;option value="99"&gt;Raspberry Swirl&lt;/option&gt;&lt;option value="100"&gt;Silver&lt;/option&gt;&lt;option value="101"&gt;Yellow Green Dream&lt;/option&gt;

  &lt;/select&gt;  &lt;/td&gt;
  &lt;td colspan="2" valign="top" class="list_cell" id="peeko_send_0"&gt;&lt;select name="free_prod_size" id="free_prod_size"&gt;&lt;option value=""&gt;Select Size&lt;/option&gt;&lt;option value=""&gt;XL&lt;/option&gt;&lt;option value=""&gt;M&lt;/option&gt;&lt;/select&gt;&lt;/td&gt;
  &lt;td valign="top" class="list_cell"&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td align="right" valign="top" class="list_cell"&gt;1&amp;nbsp;&lt;/td&gt;
  &lt;td align="right" valign="top" class="list_cell"&gt;Free&amp;nbsp;&lt;/td&gt;
  &lt;td align="right" valign="top" class="list_cell"&gt;Free&amp;nbsp;&lt;/td&gt;

&lt;/tr&gt;

&lt;!-- &lt;tr class="free" title="Free Product"&gt;
  &lt;td height="30" valign="top" class="list_cell"&gt;Maxim&lt;input type="hidden" name="free_prod_name" value="Maxim" /&gt;&lt;/td&gt;
  &lt;td valign="top" class="list_cell"&gt;
  &lt;select name="free_prod_color" id="free_prod_color"&gt;
  &lt;option value=""&gt;Select Color&lt;/option&gt;
  &lt;option value="73"&gt;2Tone Blue&lt;/option&gt;&lt;option value="74"&gt;Army Green&lt;/option&gt;&lt;option value="75"&gt;Asparagus&lt;/option&gt;&lt;option value="77"&gt;Bengal Tiger&lt;/option&gt;&lt;option value="78"&gt;Black&lt;/option&gt;&lt;option value="79"&gt;Black Pink&lt;/option&gt;&lt;option value="80"&gt;Blue Gray&lt;/option&gt;&lt;option value="81"&gt;Blue Leopard&lt;/option&gt;&lt;option value="82"&gt;Camou&lt;/option&gt;&lt;option value="83"&gt;Camou 2&lt;/option&gt;&lt;option value="84"&gt;Camou Blue&lt;/option&gt;&lt;option value="85"&gt;Camou Green&lt;/option&gt;&lt;option value="86"&gt;Charcoal&lt;/option&gt;&lt;option value="87"&gt;Dreamy Blue&lt;/option&gt;&lt;option value="88"&gt;Flaming Heart&lt;/option&gt;&lt;option value="89"&gt;Florence&lt;/option&gt;&lt;option value="90"&gt;Gray&lt;/option&gt;&lt;option value="91"&gt;Hunter Green&lt;/option&gt;&lt;option value="97"&gt;Jade&lt;/option&gt;&lt;option value="92"&gt;Leopard&lt;/option&gt;&lt;option value="93"&gt;Mosaic&lt;/option&gt;&lt;option value="94"&gt;Myrtle&lt;/option&gt;&lt;option value="95"&gt;Olive&lt;/option&gt;&lt;option value="96"&gt;Olive Dew&lt;/option&gt;&lt;option value="98"&gt;Purple Pink&lt;/option&gt;&lt;option value="99"&gt;Raspberry Swirl&lt;/option&gt;&lt;option value="100"&gt;Silver&lt;/option&gt;&lt;option value="101"&gt;Yellow Green Dream&lt;/option&gt;

  &lt;/select&gt;  &lt;/td&gt;
  &lt;td colspan="2" valign="top" class="list_cell" id="peeko_send_1"&gt;&lt;select name="free_prod_size" id="free_prod_size"&gt;&lt;option value=""&gt;Select Size&lt;/option&gt;&lt;option value=""&gt;XL&lt;/option&gt;&lt;option value=""&gt;M&lt;/option&gt;&lt;/select&gt;&lt;/td&gt;
  &lt;td valign="top" class="list_cell"&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td align="right" valign="top" class="list_cell"&gt;1&amp;nbsp;&lt;/td&gt;
  &lt;td align="right" valign="top" class="list_cell"&gt;Free&amp;nbsp;&lt;/td&gt;
  &lt;td align="right" valign="top" class="list_cell"&gt;Free&amp;nbsp;&lt;/td&gt;

&lt;/tr&gt;
 --&gt;&lt;/table&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;input type="submit" name="aa2" alt="PayPal" value="Pay Now with PayPal" onclick="return payNow()" /&gt;
    &lt;/form&gt;
</code></pre>

<p>Thanks in Advance,</p>

<p>Prasath.</p>
