Skip to main content
Participating Frequently
September 8, 2023
Question

Form script help please

  • September 8, 2023
  • 2 replies
  • 747 views

I'm a complete novice at script writing and am attempting to force 2 fields in a form to always equal 100. I got the script below from a ChatGPT application, but it doesn't work. I'm not sure why, but I know I'm doing something wrong. First of all, do I enter this (or a better script) into the properties of both fields or just one of them? And second, does anyone know a way to make this work?

var field1 = this.getField("Field1");
var field2 = this.getField("Field2");

field1.setAction("Calculate", "event.value = 100 - getField('Field2').value;");
field2.setAction("Calculate", "event.value = 100 - getField('Field1').value;");

 

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
September 8, 2023

This code doesn't make sense. It's circular logic. The value of field A is dependent on field B, but the value of field B is dependent on the value of field A... What are you trying to achieve with this code, exactly?

Participating Frequently
September 11, 2023

I see your point, and maybe I'm going about this the wrong way. the end result is that the user needs to indicate what percent of the investment is being allocated from what account. I know that code doesn't work, probably because it's recursive as you pointed out. Maybe I lock the second field and make it's value dependent on whatever is entered into the first field. I'm going to have to look into how to do that though. Like I said, scripting form fields is very new to me.

Community Expert
September 8, 2023

Hi @Chuck278300889m06,

This doesn't look like InDesign script. These API's don't exist in InDesign. This could be Acrobat script I think. What are you trying to in InDesign?

-Manan

-Manan
Participating Frequently
September 8, 2023

am attempting to force 2 fields in a form to always equal 100. That part of the form is requiring percentages of payment from different accounts, so the total can never be more than 100%.