Select dropdown and auto check the checkbox if the selected value of dropdown is not empty
<p>When people selected the dropdown and then the checkbox will be auto checked if the selected value of dropdown is not empty. But I met "sel[i] is undefined" error.</p>

<p>Javascript part:</p>

<pre><code>var chk = document.getElementsByTagName("input");
var sel = document.getElementsByTagName("select");

    for (var i=0; i&lt; sel.length; i++) {
      sel[i].onchange = function(){

        if (sel[i].value !== ''){
        chk[i].checked  = true;

    }
    else{
        chk[i].checked = false;

    }
  };
}
</code></pre>

<p>HTML part:</p>

<pre><code>&lt;form name="form1"&gt;
&lt;div class="container"&gt;
&lt;input id='checkbox_id1' name='checkbox_id1' type='checkbox' value='1' /&gt;&lt;/label&gt;&amp;nbsp;

Select
      &lt;label&gt;
          &lt;select id="select_id1" name="select"&gt;
            &lt;option value=""&gt;&lt;/option&gt;
            &lt;option value="111"&gt;111&lt;/option&gt;
            &lt;option value="222"&gt;222&lt;/option&gt;
          &lt;/select&gt;
          &lt;/label&gt;

    &lt;hr&gt;
&lt;input id='checkbox_id2' name='checkbox_id1' type='checkbox' value='1' /&gt;&lt;/label&gt;&amp;nbsp;


Select
      &lt;label&gt;
          &lt;select id="select_id2" name="select"&gt;
            &lt;option value=""&gt;&lt;/option&gt;
            &lt;option value="111"&gt;111&lt;/option&gt;
            &lt;option value="222"&gt;222&lt;/option&gt;
          &lt;/select&gt;
          &lt;/label&gt;
&lt;/div&gt;    
</code></pre>

<p></p>

<p>jsfiddle: <a href="http://jsfiddle.net/planetoid/GwEuu/" rel="nofollow">http://jsfiddle.net/planetoid/GwEuu/</a></p>
