Jquery checkbox selection
<p>I have checkbox with the same name ,I need to get the selected value of checkbox in a array.(It should exclude non selected value). I have following code.</p>

<pre><code>$(document).ready(function() {
    $(".t").change(function() {
        var allVals = [];
        $("input[name='checkbox1']:checked").each(function() {
            // alert($(this).val());
            allVals.push($(this).val());
        });
        $('#click').click(function() {
            $.each(allVals, function() {
                alert(this); // It alerts old past value also
            });
        });
    });
});


&lt;input name="checkbox1" class="t" type="checkbox" value="1"/&gt;a &lt;br/&gt;
&lt;input name="checkbox1" class="t" type="checkbox" value="2"/&gt;b &lt;br/&gt;
&lt;input name="checkbox1" class="t" type="checkbox" value="3"/&gt;c &lt;br/&gt;
&lt;input name="checkbox1" class="t" type="checkbox" value="4"/&gt;d &lt;br/&gt;
&lt;input id="click" id="button" type="button" value="click" /&gt;
</code></pre>

<p>Here is a JSFiddle with my code -> <a href="http://jsfiddle.net/manseuk/VHSrZ/" rel="nofollow">http://jsfiddle.net/manseuk/VHSrZ/</a></p>

<p>Can anyone suggest how to solve it ?</p>
