Copy link to clipboard
Copied
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?
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
...Copy link to clipboard
Copied
Check the calculation order.
Copy link to clipboard
Copied
Sorry, I m stupid and I don t understand. Can you be more specific?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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%)";
}
Copy link to clipboard
Copied
Thank you both, George and try67...both answers are correct..
You guys are awesome!!:)
Find more inspiration, events, and resources on the new Adobe Community
Explore Now