Skip to main content
Inspiring
February 12, 2022
Answered

adding checkboxes if multiple checked.

  • February 12, 2022
  • 1 reply
  • 586 views

event.value= 0; if 2 checkboxes are yes add 4 to event.value otherwise if only 1 is checked add 2. if none as stated 0.

event.value = 0;
if (this.getField("Enlargecb").value!="Yes") && (this.getField("Fey").value!="Yes") event.value=4;
else if (this.getField("Enlargecb").value!="Yes") event.value= 2;
else if (this.getField("Fey").value!="Yes") event.value=2;

but it wont let me input this code.

This topic has been closed for replies.
Correct answer Nesa Nurani

You need to put both conditions in one parentheses:

if (this.getField("Enlargecb").value!="Yes" && this.getField("Fey").value!="Yes") event.value=4;

Also != "Yes" means 'not equal yes' script will put values in field when checkbox is not checked or if your export values is not 'Yes', you need to use =="Yes" if your export values are "Yes", you can also use !="Off".

Since both yours last conditions are same value '2' you can use || (or) condition, something like this:

event.value = 0;
if (this.getField("Enlargecb").value!="Off" && this.getField("Fey").value!="Off") event.value=4;
else if (this.getField("Enlargecb").value!="Off" || this.getField("Fey").value!="Off")event.value= 2;

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
February 12, 2022

You need to put both conditions in one parentheses:

if (this.getField("Enlargecb").value!="Yes" && this.getField("Fey").value!="Yes") event.value=4;

Also != "Yes" means 'not equal yes' script will put values in field when checkbox is not checked or if your export values is not 'Yes', you need to use =="Yes" if your export values are "Yes", you can also use !="Off".

Since both yours last conditions are same value '2' you can use || (or) condition, something like this:

event.value = 0;
if (this.getField("Enlargecb").value!="Off" && this.getField("Fey").value!="Off") event.value=4;
else if (this.getField("Enlargecb").value!="Off" || this.getField("Fey").value!="Off")event.value= 2;

Inspiring
February 12, 2022

very informative. the last bit of code worked perfect for what i needed. thank you for the advice ill keep it all in mind. so || means "or" basically correct?

Nesa Nurani
Community Expert
Community Expert
February 12, 2022

Yes.