Js function with if

Community Beginner ,
May 05, 2022 May 05, 2022

Copy link to clipboard

Copied

Hi
I have four drop-down menu fields.
In each field I can select multiple options.
When I select "NOT OCCUPIED" or empty "", I want the value 1 to be given, if instead other items in the drop-down menu are selected, I want the value to be zero 0.
I put this function in a field, because I want it to give me the sum of all values
var h1 = this.getField ("PROFESSION-1"). value;
var h2 = this.getField ("PROFESSION-2"). value;
var h3 = this.getField ("PROFESSION-3"). value;
var h4 = this.getField ("PROFESSION-4"). value;
if (h1 == "NOT BUSY" && h1 == "") {var i1 = 0;} else {var i1 = 1;}
if (h2 == "NOT BUSY" && h2 == "") {var i2 = 0;} else {var i2 = 1;}
if (h3 == "NOT BUSY" && h3 == "") {var i3 = 0;} else {var i3 = 1;}
if (h4 == "NOT BUSY" && h4 == "") {var i4 = 0;} else {var i4 = 1;}
event.value = i1 + i2 + i3 + i4;

Unfortunately it doesn't work
Please, can anyone help me?

TOPICS
JavaScript

Views

39

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , May 05, 2022 May 05, 2022

1. There can't be 2 values at once so instead of '&&'(and) use || (or).

2. Dropdown field doesn't have empty "" value.

Likes

Translate

Translate
Adobe Community Professional ,
May 05, 2022 May 05, 2022

Copy link to clipboard

Copied

1. There can't be 2 values at once so instead of '&&'(and) use || (or).

2. Dropdown field doesn't have empty "" value.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 05, 2022 May 05, 2022

Copy link to clipboard

Copied

Thank you very much

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 06, 2022 May 06, 2022

Copy link to clipboard

Copied

LATEST

2. It can have, if the items in it were set using a script. It's true that it can't be done manually, though.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines