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

Text fields and number 0 problem

New Here ,
Mar 20, 2016 Mar 20, 2016

Hello.

I have very wierd problem and I hope, that somebody could help me.

I have group of 7 checkboxes, named "group". Each checkbox has his own export value. (-3, -2, -1, 0, 1, 2, 3). Then I have one text field, named "polje" where selected value is displayed. If user select check box with export value 3....text field showing number 3 and so on. I get this with this script:

getField("polje").value = this.getField("group").value;

So far everything works perfect. Now...problem. I have another textfield, named "procent". His mission is to show additional text by specific value.

If  field "polje" showing value 1, textfield "procent" must display "30%", if value is 2 then "60%"....and so on. Everything works fine...only with value 0...then textfield stay empty but it should display "0%". I dont know why.

Script I use:

var p = this.getField("polje").value;

if (p == "") {

    event.value = "";

}

else if (p == 0) {

    event.value = "(0%)";

}

else if (p == 1) {

    event.value = "(30-40%)";

}

else if (p == 2) {

    event.value = "(60-70%)";

}

else if (p == 3) {

    event.value = "(90-100%)";

}

else if (p == -1) {

    event.value = "(-30-40%)";

}

else if (p == -2) {

    event.value = "(-60-70%)";

}

else if (p == -3) {

    event.value = "(-90-100%)";

}

Where I do something wrong?

TOPICS
Acrobat SDK and JavaScript
774
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 , Mar 20, 2016 Mar 20, 2016

You should get the field values as strings and compare to strings, something like:

var p = this.getField("polje").valueAsString;

if (p === "") {

    event.value = "";

}

else if (p === "0") {

    event.value = "(0%)";

}

else if (p === "1") {

    event.value = "(30-40%)";

}

else if (p ==="2") {

    event.value = "(60-70%)";

}

else if (p === "3") {

    event.value = "(90-100%)";

}

else if (p === "-1") {

    event.value = "(-30-40%)";

}

else if (p === "-2") {

    event.value = "(-60-70%)";

}

else if (p === "-3") {

    even

...
Translate
Community Expert ,
Mar 20, 2016 Mar 20, 2016

Check the calculation order.

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
New Here ,
Mar 20, 2016 Mar 20, 2016

Sorry, I m stupid and I don t understand. Can you be more specific?

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
Community Expert ,
Mar 20, 2016 Mar 20, 2016
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
New Here ,
Mar 20, 2016 Mar 20, 2016

OK...I watch tutorial and I dont know if you understand, what is my problem. Everything works fine...like I want. Everything but...only when the value of text field "polje"is 0...then text field act...like there is no value or like the field is empty. There is no calculation script or calculation itself...just values. One field get value of selected check box and display this value..other field check value of first field and add proper text (like 10%, 20%...). This are not calculated values in procents...more like strings. You may replace this procents values with strings if you want.

So...main problem is, that when value is 0...other field doesnt recognise that and act like field is empty. Anyone can tell me why?

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
Community Expert ,
Mar 20, 2016 Mar 20, 2016

When you use the "==" operator JS attempts to cast the values you're comparing to the same type, and when a blank string is converted to a number, it translates as zero. So one possible solution is to use the "===" operator instead, which performs a strict comparison and doesn't cast any values.

To demonstrate this issue run this code:

""==""; // returns true

""==0; // returns true

""===""; // returns true

""===0; // returns false

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 ,
Mar 20, 2016 Mar 20, 2016

You should get the field values as strings and compare to strings, something like:

var p = this.getField("polje").valueAsString;

if (p === "") {

    event.value = "";

}

else if (p === "0") {

    event.value = "(0%)";

}

else if (p === "1") {

    event.value = "(30-40%)";

}

else if (p ==="2") {

    event.value = "(60-70%)";

}

else if (p === "3") {

    event.value = "(90-100%)";

}

else if (p === "-1") {

    event.value = "(-30-40%)";

}

else if (p === "-2") {

    event.value = "(-60-70%)";

}

else if (p === "-3") {

    event.value = "(-90-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
New Here ,
Mar 20, 2016 Mar 20, 2016
LATEST

Thank you both, George and try67...both answers are correct..

You guys are awesome!!:)

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