Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

What is wrong in this JavaScript code?

Explorer ,
Sep 01, 2016 Sep 01, 2016

Untitled.png

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;

}

TOPICS
Acrobat SDK and JavaScript , Windows
945
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Sep 01, 2016 Sep 01, 2016

Change those two lines to:

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

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

Note that it's else, not Else.

Translate
LEGEND ,
Sep 01, 2016 Sep 01, 2016

Change those two lines to:

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

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

Note that it's else, not Else.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 01, 2016 Sep 01, 2016

Thanks for reply.

Let me test it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 02, 2016 Sep 02, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 02, 2016 Sep 02, 2016

Hi, i tried.. but not working..

see this error.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 02, 2016 Sep 02, 2016

JavaScript is case sensitive. That is, you cannot write Else or ELSE when you mean else.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 02, 2016 Sep 02, 2016

Yes, done..

please see this..

the calculation is going wrong.

why?

The answer would be like this:

(Total supervision hours / total experience hours ) * 100

so, (60/60)*100 = 100.

but why the answer went "100000" ?

thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 02, 2016 Sep 02, 2016

It's not 100000, it's 10000%. I suspect you set the field up with a percent format. To display 100%, you'd set the field value to 1. To display 31.5%, you'd set the field value to 0.315. When you set it to 100, it gets displayed as 100 * 100, or 10000%

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 02, 2016 Sep 02, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 02, 2016 Sep 02, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 02, 2016 Sep 02, 2016
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines