Copy link to clipboard
Copied
I have a form where I want an answer in lateralside1 but the decision of what types into this field is from text 23. IF Text23 is <0 I want Right in Lateralside 1 and if >0 then I want the word Left. I tried this script but it didn't work. Any one know what I am missing? Thank you in advance.
var number = this.getField("Text23").value; // Get the value from Text23
if (number > 0) {
event.value = "Left"; // If the number is greater than 0, display "Left"
} else if (number < 0) {
event.value = "Right"; // If the number is less than 0, display "Right"
} else {
event.value = ""; // If the number is exactly 0, leave the field empty
}
Copy link to clipboard
Copied
Where did you put the script?
It should go under 'Calculate' tab as custom calculation script of "Lateralside 1" field.
Copy link to clipboard
Copied
Hi Nesa, I have put the script there and it likes the code but it still is not displaying the word left or right in the fields. Right now Field23 has the number -.35 in it so it should display the word Right.
Copy link to clipboard
Copied
Is your field named "Text23" or "Field23"?
Check that your field name is correct, also you can check console (CTRL+J) for any errors.
Copy link to clipboard
Copied
It is Text23. I appreciate your help. This one has stumped me.
Copy link to clipboard
Copied
Did you solve it or you need further help?
Copy link to clipboard
Copied
No, I don't have it yet. Can I send the form to you? There is something I am missing here.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Your field is named "TEXT23" not "Text23" JavaScript is case-sensitive, so change field name in the script to "TEXT23" and it will work.
Copy link to clipboard
Copied
You are a genius! I didn't know about case sensitive so good tip. Have a wonderful day.
Copy link to clipboard
Copied
If I could ask one more question. I have a text box that I want to turn red if the number is over 5 and stay transparent if under 5. This is what I have for a script.
if(event.value >= 5)
event.target.fillColor= color.red;
if(event.value <= 5)
event.target.fillColor= color.transparent;
The problem is that if it turns red and then the number changes the red box colour won't go away. Is there another script for that?
Copy link to clipboard
Copied
You can't use equal in both conditions since if true it will always be last condition.
Copy link to clipboard
Copied
I see what is happening there, when it does turn red for the over 5, and then the answer is corrected it will not turn to transparent. It is changing the appearance to red. I have to go in and manually change it to no colour. This does not work when someone is using the form of course. I took out the last part of the script and it still works for changing to red. So, is the problem in the last part in changing it to transparent?
Copy link to clipboard
Copied
I figured it out, I just took the =- sign out, like you said above. It works perfectly now. - Thank you once again.