jQuery in Action, 2nd edition*
The moose likes HTML, CSS and JavaScript and the fly likes Is Checkbox checked by name? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Is Checkbox checked by name?" Watch "Is Checkbox checked by name?" New topic
Author

Is Checkbox checked by name?

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1439
    
    1
This code seems to always act as is check box is checked even when I un check it.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

The expression $("input[name='usertextmsgcntrl']:checked") always returns a jQuery wrapped set, which is truthy, so the expression always evaluates to true.

What you want to check is the length of the set. If the checkbox is checked the wrapped set will not be empty.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1439
    
    1
Thanks Bear.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is Checkbox checked by name?