자바스크립트에서 체크박스 Array 값 사용하기
Client Side
<form method="get">
<input type="checkbox" name="options[]" value="1" />
<input type="checkbox" name="options[]" value="2" />
<input type="checkbox" name="options[]" value="3" />
<input type="submit" value="Go!" />
</form>
function getCheckboxes(selector) {
var arr = [];
var checkboxes = document.querySelectorAll(selector + ":checked");
for (var i = 0; i < checkboxes.length; i++) {
arr.push(checkboxes[i].value);
}
return arr;
}
getCheckboxes('input[type="checkbox"]');
Server Side
$checked = $_GET['options'];
for($i=0; $i < count($checked); $i++){
echo "Selected " . $checked[$i] . "<br/>";
}