-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkbox_to_array.html
77 lines (68 loc) · 1.85 KB
/
checkbox_to_array.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>checkbox to array</title>
</head>
<body>
<ul>
<li>
<input name="items[]" type="checkbox" value="c1">
</li>
<li>
<input name="items[]" type="checkbox" value="c2">
</li>
<li>
<input name="items[]" type="checkbox" value="c3">
</li>
<li>
<input name="items[]" type="checkbox" value="c4">
</li>
<li>
<input name="items[]" type="checkbox" value="c5">
</li>
<li>
<input name="items[]" type="checkbox" value="c6">
</li>
<li>
<input name="items[]" type="checkbox" value="c7">
</li>
<li>
<input name="items[]" type="checkbox" value="c8">
</li>
<li>
<input name="items[]" type="checkbox" value="c9">
</li>
<li>
<input name="items[]" type="checkbox" value="c10">
</li>
</ul>
<div id="result"></div>
<button id="sendBtn" type="submit">Send</button>
<script src="jquery-3.1.1.min.js"></script>
<script>
$(function() {
$('#sendBtn').click(function() {
var checkboxs = $('input[name="items\\[\\]"]:checked');
alert('checked ' + checkboxs.length + ' items');
var values = checkboxs.map(function() {
return $(this).val();
})
.get();
var params = {
"id": 24,
"items": values,
};
$.ajax({
"data": params,
"success": function(data) {
$('#result').html(data);
},
"type": "GET",
"url": "processing.php",
});
});
});
</script>
</body>
</html>