0

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

2 Answers 2

1

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
}
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.