Skip to main content
CelanieMeyer
Participant
April 26, 2019
質問

JavaScript Troubleshooting

  • April 26, 2019
  • 返信数 2.
  • 339 ビュー

Hi Everyone,

I am an amateur at JavaScript, and hope someone can show me where I am going wrong.

My script is:

event.value = "";

var Text1 = this.getField("Text1").value;

if (Text1!="") {

     if (Number(Text1)>20,Number(Text1)<51) event.value = Number(Text1)-20;

     else if (Number(Text1)>50) event.value = 30

else event.value = 0;

}

Which should:

1. If the input value is under 20, output is zero,

2. If the input value is between 20 and 51, output is input value minus 20

3. If the input value is over 50, output value is 30

It works mostly, however, input values under 20 are giving negatives, not zero.

Where have I gone wrong?

このトピックへの返信は締め切られました。

返信数 2

Bernd Alheit
Community Expert
Community Expert
April 26, 2019

Try this:

event.value = "";

var Text1 = this.getField("Text1").valueAsString;

if (Text1!="") {

    Text1 = Number(Text1);

    if (Text1>20 && Text1<51) event.value = Text1-20;

    else if (Text1>50) event.value = 30;

    else event.value = 0;

}

CelanieMeyer
CelanieMeyer作成者
Participant
April 26, 2019

Great! Thank worked a charm - I'll remember the multiple conditions convention next time