Skip to main content
Participant
February 23, 2024
Question

Custom calculating two auto populated fields based on a drop down selection?

  • February 23, 2024
  • 2 replies
  • 443 views

Hello all. I'm making a custom D&D character sheet with auto populated fields. However, I'm having trouble with one specific part. I've made a drop down list (F1) with a selection of classes. Based on which class is chosen, the saving throws (F4) should be auto populated by adding ability modifiers (F2) and prof bonus (F3).  Both F2 and F3 are also auto populated based on other fields. Heres the example of what I've got so far -

Var Pro=this.getField("PB").value;
Var St=this.getField("Strength").value;
Var De=this.getField("Dexterity").value;
Var Co=this.getField("Constitution").value;
Var In=this.getField("Intellegence").value;
Var Ch=this.getField("Charisma").value;
Var Wi=this.getField("Wisdom").value;
if(event.value==Barbarian){
this.getField("SavS").value=Pro+St;
this.getField("STD").value=De;
this.getField("STCo").value=Co;
this.getField("STI").value=In;
this.getField("STCh").value=Ch;
this.getField("STW").value=Wi;
}

This shows the example with only one class, but you get the point. My problem arrises with the Vars, it keeps showing as 'SyntaxError: missing; before statment 1: at line 2'. I would like to simplify this and just learn it, so if anyone has any advice I would appreciate it!

This topic has been closed for replies.

2 replies

Nesa Nurani
Community Expert
Community Expert
February 23, 2024

As stated by Bernd it should be var not Var, but also when using string in condition you should use quotes:

if(event.value==Barbarian){

should be:

if(event.value=="Barbarian"){

Also, you may want to get values as numbers so you avoid get concatenated result instead of sum:

var Pro = Number(this.getField("PB").valueAsString);
var St = Number(this.getField("Strength").valueAsString);

 

Participant
February 23, 2024

Omigosh worked like a charm!!!! Thank you so much. 

Bernd Alheit
Community Expert
Community Expert
February 23, 2024

Use var not Var