Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
Great! Thank worked a charm - I'll remember the multiple conditions convention next time