Skip to content

Instantly share code, notes, and snippets.

@jasonsarino
Last active August 29, 2015 14:25
Show Gist options
  • Save jasonsarino/fa0df25f898c4d09764b to your computer and use it in GitHub Desktop.
Save jasonsarino/fa0df25f898c4d09764b to your computer and use it in GitHub Desktop.
multiple checkbox save to database
index.php
<script type="text/javascript">
function save(){
var formdata = $('#frm').serialize();
$.ajax({
url: "save.php",
type: "POST",
data: formdata,
success: function(result){
console.log(result);
}
});
}
</script>
<form method="POST" name="fmr" id="frm">
<input type="checkbox" name="chk[]" id="chk" value="A"> A<br>
<input type="checkbox" name="chk[]" id="chk" value="B"> B<br>
<input type="checkbox" name="chk[]" id="chk" value="C"> C<br>
<input type="checkbox" name="chk[]" id="chk" value="D"> D<br>
<input type="checkbox" name="chk[]" id="chk" value="E"> E<br>
<input type="button" value="Submit" class="submit" onclick="save()">
</form>
save.php
$chk = $_POST['chk'];
echo implode("|", $chk);
output: A|B|C
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment