thar
thar

Reputation: 1104

jQuery validate input type checkbox value

I'am stoked at a basic task. I want to check if a checkbox i checked or not using jQuery.

The problem is that the if condition is being executed no matter its checked or not.

What am I doing wrong?

($('#betingelser').prop('checked', false)){
    console.log("checked if");
    isValid = false;
    result += 'Venligst accepter betingelserne<br>';        
}

Thanks for your time

Thar

Upvotes: 0

Views: 47

Answers (2)

PiotrK
PiotrK

Reputation: 1552

By passing false as the second argument, you're actually telling the checkbox to check itself. Just delete this second argument and it should work fine.

Upvotes: 0

Milind Anantwar
Milind Anantwar

Reputation: 82231

You are not having correct condition in if part. you are setting the value as false by using $('#betingelser').prop('checked', false) in it. To check whether checkbox is check use:

if($('#betingelser').is(':checked')){
   //rest code
}

Upvotes: 1

Related Questions