Conditional fields if one field is empty, the others to be empty also, if not empty, for it to have a percentage or grade.
Copy link to clipboard
Copied
I want the second line to be empty if the marks (like it is now) to be empty. I have this in the % field under progress at the moment (where the 17 currrently is)
((DataTest +StudentInvestigation)/30)*100
and in the result section I have this.
var perc = this.getField("Percentage2").valueAsString;
if (perc=="") event.value = "";
else {
perc = Number(perc);
if (perc<25) event.value = "E";
else if (perc<45) event.value = "D";
else if (perc<65) event.value = "C";
else if (perc<85) event.value = "B";
else event.value = "A";
}
I'm not sure how to add the "if ___ field is empty" part to it.
Copy link to clipboard
Copied
Do you mean for the first calculation? You can use something like this:
var s1 = this.getField("DataTest").valueAsString;
var s2 = this.getField("StudentInvestigation").valueAsString;
if (s1=="" || s2=="") event.value = "";
else event.value = ((Number(s1)+Number(s2))/30)*100;
Copy link to clipboard
Copied
Yes thank you,
and the Grade field as well.
Copy link to clipboard
Copied
The script above already does that.
Copy link to clipboard
Copied
Yes it does for the percentage, but in the result field it still comes up with an "E" even though the percentage is nothing.
Copy link to clipboard
Copied
Oh never mind, its because I did the input wrong for the last one. Thank you again.
Copy link to clipboard
Copied
Hi,
Sorry now, when I change the numbers it doesn't update the grade in the result section.
Copy link to clipboard
Copied
Check the JS Console (Ctrl+J) for error messages.

