Reputation: 11302
I have a form with image thumbnails to select with checkboxes for downloading. I want an array with the images in jQuery for an Ajax call.
2 questions:
- On the top of the table there is a checkbox to toggle all checkboxes that I want to exclude from the mapping. I had a look at jQuery's .not() but I can't implement it with the :checkbox selector
- is the following example code correct?
$(document).ready(function() {
$('#myform').submit(function() {
var images = $("input:checkbox", this).map(function() {
return $(this).attr("name");
}).get().join();
alert(images); // outputs: ",check1,check2,check3"
return false; // cancel submit action by returning false
});
}); // end doc ready
HTML:
<form id="myform" action="" >
<input type="checkbox" id="toggleCheck" onclick="toggleSelectAll()" checked="checked" ><br />
<input type="checkbox" name="001.jpg" checked="checked" /><br />
<input type="checkbox" name="002.jpg" checked="checked" /><br />
<input type="checkbox" name="003.jpg" checked="checked" /><br />
<br />
<input type="submit" value="download" >
</form>
Upvotes: 5
Views: 9680
Reputation: 4792
You can chain like the following
$('input:checkbox:not(#toggleall)').after('this is selected');
see the example code here http://jsbin.com/ofecu and http://jsbin.com/ofecu/edit
Upvotes: 0
Reputation: 630429
You can exclude it via the ID, like this:
$("input:checkbox", this).not("#toggleCheck").map(....
This would exclude the select all toggle from the mapping.
Upvotes: 11