I have this code:
<input type="checkbox" id="checkbox" value="11">
<input type="checkbox" id="checkbox" value="10">
<div id="log"></div>
$("input").click(function() {
$("#log").html( $(":checked").val() + " is checked!" );
});
If I start by checking the first checkbox, then the next, it will add: 11 is checked.
How can I do so, it takes ALL submitted checkbox values – like:
11,10, is checked.
And is it possible to extract those values with php so it looks like this:
10
11
Without the “,”
UPDATE:
$('input[type="submit"]').click(function() {
var kolort = $('input[type="checkbox"]:checked').val();
var output = $(this).text() + ", " + kolort;
/*
$('input[type="checkbox"]:checked').each(function(index) {
output += $(this).text() + ", ";
});*/
alert(output + "is checked!");
});
I now have this. ALthough, it just prints out ONE of the values and not both. How can I do so it take values from EACH input?
You can use jQuery’s
.each()API:Test page: http://pastebin.com/LVuLUthB
As for removing the commas, there will be no commas when processing in PHP. Checkboxes are sent as an array. What you want to do is:
And then in the PHP: