How to get option value of only the selected checkboxes?
<p>I want to get option value of only selected checkbox, but I am getting value from all the checkboxes.</p>

<p>My HTML code:      </p>

<pre><code> &lt;div class= "outer"&gt;
    &lt;div class="inner" id="inner"&gt;
    &lt;input type="checkbox" name="machine" value="plane"&gt;BBQ Sauce&lt;br&gt;
      &lt;select class="weight" name="m2" id="m2"&gt;
        &lt;option value="1"&gt;Light&lt;/option&gt;
        &lt;option value="2"&gt;Normal&lt;/option&gt;
        &lt;option value="3"&gt;Extra&lt;/option&gt;
      &lt;/select&gt;

    &lt;/div&gt;
    &lt;div class="inner" id="inner"&gt;
    &lt;input type="checkbox" name="machine" value="plane"&gt; Alfredo Sauce&lt;br&gt;
       &lt;select class="weight" name="m2" id="m2"&gt;
          &lt;option value="1"&gt;Light&lt;/option&gt;
          &lt;option value="2"&gt;Normal&lt;/option&gt;
          &lt;option value="3"&gt;Extra&lt;/option&gt;
       &lt;/select&gt;
    &lt;/div&gt;
 &lt;/div&gt;
&lt;input type="submit" value="Submit"&gt;
</code></pre>

<p>My JavaScript code:</p>

<pre><code> function myAction(){
   var vals = [];
   var machine = document.getElementsByName('machine');

   var m2 = document.getElementById('m2');

   for(var i=0, n= machine.length; i&lt;n; i++){
        if(machine[i].checked){
            vals.push(m2.value);
        }
    }
 }
</code></pre>