Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Jquery to test checkboxes inside if statement not working

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
0
0
US
I ran into an issue where I couldn't get my test of a checkbox wouldn't work. Using JQuery inside of an "if" statement seemed to not work but when I took it out of the if statement and put the result into a variable it worked fine.

For example, if I do it the following ways:

Code:
if($("input:checkbox").is(":checked") == false)
{
    // Do something if not checked
}

OR

Code:
if(!$("input:checkbox").is(":checked"))
{
    // Do something if not checked
}

They don't seem to work. It will always treat it as "true" regardless of whether the checkbox is checked.

But if I do this:

Code:
allFilled = $("input:checkbox").is(":checked");

if(!allFilled)
{
    // Do something if not checked
}

It works fine.

Why can't you put the JQuery inside the "if" statement?

Thanks,

Tom

 
Found it.

IN my code, I had a semicolon right after the if statement and that caused it to always go to the next statement.

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top