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

Calculation will not stop

Community Beginner ,
Oct 02, 2017 Oct 02, 2017

I am using Adobe Pro and I am trying to use a radio button to complete a calculation.  There's text field ("CourseName"), another field formatted as a number field ("Hours") and the radio button ("HourType").  The user enters the course name, and then enters how many credit hours received for the course.  The radio button performs a calculation depending on if the user selects Semester Hours (export value is SH) or Quarter Hours (export value is QH).  If the user selects "SH" then nothing changes, but if they select "QH", the "Hours" value is multiplied by 0.6667.   I'm using the following custom calculation script on the "Hours" field:

var total = Number(this.getField("Hours").value);

var type = this.getField("HourType").value;

if (type=="QH") {

   event.value = total * 0.6667;

} else

   event.value = total;

The script works fine until I toggle back and forth. Each time I go from QH to SH and then back to QH..it performs the calculation again, which shrinks the number for the QH.  I need to be able to alternate between the two radio button options and not have the QH option continuously recalculate.

So, if 15 is entered into "Hours" and the user selects the "QH" button, the "Hours" field should change to 10.  If the user changes their mind and selects the "SH" button, the "Hours" should revert back to 15......and if they decide to go back to "QH", the "Hours" should calculate 10 again...right now, it's dropping to 6.67.

I hope I'm just overlooking something fairly simple...any input would be greatly appreciated

TOPICS
Acrobat SDK and JavaScript , Windows
276
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 ,
Oct 02, 2017 Oct 02, 2017

You cannot use the "Hours" field as both input and output of your calculation. When you do that, it will always behave the way you are describing. You need two fields: One that the user enters the "Hours" information, and a second one that then contains the results of your calculation.

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 Beginner ,
Oct 02, 2017 Oct 02, 2017
LATEST

Thank you!  I was hoping it was something simple.  I added another text field and moved the "Hours" script to the new text field custom calculation...works perfectly!

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