Skip to main content
Onsightclimb
Participating Frequently
March 20, 2016
Answered

Text fields and number 0 problem

  • March 20, 2016
  • 1 reply
  • 879 views

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?

This topic has been closed for replies.
Correct answer George_Johnson

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?


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%)";

}

1 reply

Bernd Alheit
Community Expert
Community Expert
March 20, 2016

Check the calculation order.

Onsightclimb
Participating Frequently
March 20, 2016

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