Skip to main content
Known Participant
Sep 2, 2016 3:41 AM UTC
Answered

What is wrong in this JavaScript code?

Please fix this error.

var Exp = 'totalexperience';

var Sup = 'totalsup';

var f = this.getField(Exp).value;

var a = this.getField(Sup).value;

if(f==0)||(a==0)

{

event.value=f+a;

}

Else if(f!=0)||(a!=0)

{

event.value=a/f*100;

}

This topic is closed to new replies. Start a new post to keep the conversation going.
George_JohnsonCorrect answer
Inspiring
Sep 2, 2016 6:36 AM UTC

Change those two lines to:

if (f == 0 || a == 0)

else if (f != 0 || a != 0)

Note that it's else, not Else.

10 replies

Legend
Sep 2, 2016 11:24 AM UTC

just change the code do you do not muliply by 100.

Translate
Legend
Sep 2, 2016 9:42 AM UTC

100000 would be very hard to explain, but it's actually 10000 which is very easy to explain. I imagine you've defined this as a percentage field. If I remember correctly, a percentage field expects a value which is a fraction (such as 0.6) and displays it as a percentage (such as 60%). Either don't multiple by 100, or don't use a percentage field.

Translate
Known Participant
Sep 2, 2016 10:06 AM UTC

i am confusing, please write down here the code. thanks

Translate
George_JohnsonCorrect answer
Inspiring
Sep 2, 2016 6:36 AM UTC

Change those two lines to:

if (f == 0 || a == 0)

else if (f != 0 || a != 0)

Note that it's else, not Else.

Translate
Known Participant
Sep 2, 2016 6:40 AM UTC

Thanks for reply.

Let me test it.

Translate
Legend
Sep 2, 2016 7:56 AM UTC

And by the way, it's JavaScript (one word, no space), not Java. Java is something entirely different.

(Moderation: topic's title edited)

This becomes very important if searching the web for advice, as Java is going to look enough like JavaScript to really mess you up.

Translate