Getting value from checkbox

I have a form with the following checkbox:

<input type=“checkbox” name=“Invoice” value=“Yes” style=“position:relative; margin-top:13px;” />

Then using jquery for validation, and I dont think Im using the right way.


$('#submit').click(function () {
var hemail = $('input[name=Hemail]');
var hrooms = $('input[name=Hrooms]');
var invoice = $('checkbox[name=Invoice]');

var data = '&Hname=' + hname.val() + '&RazSoc=' + razsoc.val() + '&Cif=' + cif.val() + '&Cname=' + cname.val() + '&Phone=' + phone.val() + '&Address=' + address.val() + '&Address2=' + address2.val() + '&BAddress=' + baddress.val() + '&BAddress2=' + baddress2.val() + '&Countries=' + countries.val() + '&Hwebsite=' + hwebsite.val() + '&Hemail='  + hemail.val() + '&Hrooms=' + hrooms.val() + '&Invoice=' + invoice.val() + '&Name=' + name.val() + '&JTitle=' + jtitle.val() + '&Email=' + email.val() + '&Ctel=' + ctel.val();
}

The two examples above var invoice = $(‘checkbox[name=Invoice]’); are to show the other parts which are working fine, but I dont seem to be able to gather the value from the checkbox when its checked, so wondered what was the right way

Sorry, school boy error…

var invoice = $(‘input[name=Invoice]’);

This worked, but when I checked it without checking the checkbox, it still came back with the Yes value, so Im guessing I need to somehow only read the value when its checked.

Again looks like I got this osrted:

var invoice = $(‘input[name=Invoice]:checked’);

then a little if statement before the email processing to sort out the undefined bit…

seems to be workign fine, thanks