Very, VERY new to JavaScript here.. I've been trying to make a character sheet in acrobat auto-populating, and so far I've had good success with most things, until coming to comparing two values.
MaxDex can be an integer greater than 0, and DexTempMod and DexMod can be integers between -10 and 10. The code below works great if dexTempMod and DexMod are positive - if they're greater than MaxDex, it will output MaxDex instead.
But if DexTempMod or DexMod are negative values, it still outputs MaxDex, despite the others being lower. I've tried parsing them into floats after some research, thinking they might be strings, but it still doesn't work.
If it's just a limitation of Acrobat, that's fine, but I'm a little stumped.
if (this.getField("MaxDex").value == ""){if (this.getField("DEXTempMod").value == "")
{event.value = this.getField("DEXMod").value}
else {event.value = this.getField("DEXTempMod").value};
}
else {if (Float.parseFloat(this.getField("MaxDex").value) < Float.parseFloat(this.getField("DEXTempMod").value) || Float.parseFloat(this.getField("DEXMod").value))
{event.value = this.getField("MaxDex").value}
else {if (this.getField("DEXTempMod").value == "")
{event.value = this.getField("DEXMod").value}
else {event.value = this.getField("DEXTempMod").value};}
}
You don't need to use Float.parseFloat. Just be sure the fields are formatted to be numbers in the field properties.
There's no comparison after the || in your outer else statement so any value will evaluate as true in your else statement because even an empty field has a value.