Will Curran
Will Curran

Reputation: 7110

How to get value for checkbox in JQuery?

I'm using JQuery to POST a form. I'm having trouble getting the proper value from this field:

<input type="checkbox" name="facebook" value="true" checked="checked" id="facebook"/>

My JQuery:

var facebook = $("input#facebook").val();

I realize now that I'm getting the value with is always "true" regardless of being checked or not. So how do I get whether it's checked or not?

Upvotes: 2

Views: 2789

Answers (1)

amurra
amurra

Reputation: 15401

var facebook = $('input#facebook').is(':checked');

Upvotes: 9

Related Questions