I want to get the values of the checked checkbox here but it is undefined because it becomes an array.. Please help me how to do it.. thank you..
<form>
<input type="checkbox" value="a" name="letter[]" />
<input type="checkbox" value="b" name="letter[]" />
<input type="checkbox" value="c" name="letter[]" />
<input type="button" value="submit" onclick="rani()" />
</form>
<script>
function rani(){
$.ajax({
type:"post",
url:"ajax.php",
data:{
radha:$("[name=letter]").val(),
},
success:function(msg){
alert(msg);
}
})
}
</script>
Here you will get selected checkbox values in a variable checkbox_value
and later split by |
.
$("#btn_").on('click', function () {
var checkbox_value = "";
$(":checkbox").each(function () {
var ischecked = $(this).is(":checked");
if (ischecked) {
checkbox_value += $(this).val() + "|";
}
});
alert(checkbox_value);
// your awesome code calling ajax
});
Sample Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With