How to conditionally check the value of checkbox?