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

Coding for Right or LEft

Explorer ,
Mar 11, 2025 Mar 11, 2025

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
}

TOPICS
Create PDFs
446
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 11, 2025 Mar 11, 2025

Where did you put the script?

It should go under 'Calculate' tab as custom calculation script of "Lateralside 1" 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 ,
Mar 12, 2025 Mar 12, 2025

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. 

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 12, 2025 Mar 12, 2025

Is your field named "Text23" or "Field23"?

Check that your field name is correct, also you can check console (CTRL+J) for any errors.

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 ,
Mar 12, 2025 Mar 12, 2025

It is Text23.  I appreciate your help. This one has stumped me. 

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 12, 2025 Mar 12, 2025

Did you solve it or you need further help?

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 ,
Mar 12, 2025 Mar 12, 2025

No, I don't have it yet. Can I send the form to you? There is something I am missing here. 

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 ,
Mar 12, 2025 Mar 12, 2025

I see I can add this.  

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 12, 2025 Mar 12, 2025

Your field is named "TEXT23" not "Text23" JavaScript is case-sensitive, so change field name in the script to "TEXT23" and it will work.

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 ,
Mar 12, 2025 Mar 12, 2025

You are a genius! I didn't know about case sensitive so good tip.  Have a wonderful day. 

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 ,
Mar 12, 2025 Mar 12, 2025

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?

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 12, 2025 Mar 12, 2025

You can't use equal in both conditions since if true it will always be last condition.

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 ,
Mar 12, 2025 Mar 12, 2025

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? 

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 ,
Mar 12, 2025 Mar 12, 2025
LATEST

I figured it out, I just took the =- sign out, like you said above. It works perfectly now. - Thank you once again. 

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