First of all, Java and Javascript are two different beast, it one of them but no both.
As far as I can see, the question is not related to PDF.
Did you named a field "5" ?
var secondValue = this.getField("5");
It is rather unusual.
Working out something of your code is more a guess than anything else.
var firstValue = "3:00";
var secondValue = "3:05";
if (firstValue=="3:00" || secondValue=="3:15") event.value = "5";
else event.value = Number(firstValue) + Number(secondValue);
This way, we don't have to guess what is doing the code.
Looks like you are dealing with time values, you can't expect conversion to number to be handled correctly.
And your coding style is bad, it save 2 enter key typing at the expense of readability, this is better.
var firstValue = this.getField("valueOne"). ValueAsString;
var secondValue = this.getField("5");
if (firstValue=="3:00" || secondValue=="3:05")
event.value = "5";
else
event.value = Number(firstValue) + Number(secondValue);
Asking questions is a skill[
^]
Some guidelines for posting questions in the forums[
^]
[Update]
Quote:
As it is apparently abundantly clear, I am not a professional coder. I have no idea what I'm doing - hence the "bad code" and not knowing the difference between Java and JavaScript.
We can't guess what is not told.
Advice: Learn language and programming properly with some tutorials, not by starting with a personal project.
What you do is like trying to get a driving license by winning a Formula 1 Grand Prix, it don't work like that.
Quote:
I got a Syntax error for an illegal character on line 2.
Did you forgot to tell us that you had the same error message in code from question?
Rule of thumb, to do the same thing on 2 fields, use the same syntax.
Try:
var firstValue = this.getField("Text23"). ValueAsString;
var secondValue = this.getField("Text24").ValueAsString;
Quote:
Would it be easier to have a set value of 5 in another box? So I input a value in Text23 + other box with set value of 5 = result appears in Text24.
Advice: explain the meaning of what you are doing.
I have a form to do this ...
I read value from 2 fields, their meaning is ...
I do this operation which mean ... , the result means ...
I store result in ... field ...