You are viewing limited content. For full access, please sign in.

Question

Question

Running an if statement only when a user unchecks a checkbox.

asked on October 12, 2022

Hello,

 

Essentially what the title says. I want to be able to run an if statement when a user unchecks a checkbox. This I would assume is similar to the code used for when a user checks a checkbox, but I've tried a lot of variations and have found nothing that works. This is the code I currently use for when a checkbox is checked:

 

if($('input[id = "Field54-0"]').is(':checked')) {

 

Any help will be much appreciated.

 

Thank you!

0 0

Answer

SELECTED ANSWER
replied on October 12, 2022

You could just invert the result using the logical not ( ! ) operator at the front.

if(!$('input[id = "Field54-0"]').is(':checked'))

 

Alternatively, you could invert it using the jquery :not() selector.

:not() Selector | jQuery API Documentation

if($('input[id = "Field54-0"]').is(':not(:checked)'))
0 0
replied on October 13, 2022

You my friend are a genius! Thank you for all your help!

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.