• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Js function with if

Participant ,
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

278

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

Community Expert , 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.

Votes

Translate

Translate
Community Expert ,
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.

Votes

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
Participant ,
May 05, 2022 May 05, 2022

Copy link to clipboard

Copied

Thank you very much

Votes

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 Expert ,
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.

Votes

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