Reputation: 317
I have a form with a checkbox and I am using JQuery to submit the values so that I can pick them up on the next page.
However, my checkbox always shows an 'on' even though it is unchecked.
How can I detect the right value whilst passing the array to the next page? My JQuery code:
$('#btnSubmit').click(function() {
var myData = [];
var rows = $('#customFields').find('tr');
rows.find('td input').each(function() {
myData.push($(this).val());
});
alert(myData);
$('#invoiceitems').val(myData);
$('#form1').submit();
});
Thanks
Upvotes: 1
Views: 56
Reputation: 10896
try something like this
rows.find('td input').each(function() {
if($(this).is(':checkbox')){
myData.push(this.checked);
}else{
myData.push($(this).val());
}
});
Upvotes: 1