Last active
August 29, 2015 14:25
-
-
Save jasonsarino/fa0df25f898c4d09764b to your computer and use it in GitHub Desktop.
multiple checkbox save to database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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