Skip to main content
Known Participant
September 2, 2016
Answered

What is wrong in this JavaScript code?

  • September 2, 2016
  • 3 replies
  • 1147 views

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 has been closed for replies.
Correct answer George_Johnson

Change those two lines to:

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

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

Note that it's else, not Else.

3 replies

Legend
September 2, 2016

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

Legend
September 2, 2016

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.

Known Participant
September 2, 2016

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

George_JohnsonCorrect answer
Inspiring
September 2, 2016

Change those two lines to:

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

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

Note that it's else, not Else.

Known Participant
September 2, 2016

Thanks for reply.

Let me test it.

Legend
September 2, 2016

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.