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

code work in document JavaScript and not work in checkbox JavaScript

Enthusiast ,
Apr 21, 2018 Apr 21, 2018

Copy link to clipboard

Copied

Hi expert...

I was developing new form of (Attendance Statement), I have 16 group of Check Boxes (in one page)  , Every Group is about 20 Check boxes because it represent the Month without the Week ends!, The Problem is that code work very good inside (document JavaScript ) so  i call the function from it to every checkbox, now i tried to delete the function from the Document java script because every page is 16 Trainer name, and if i add another page and i will do that, that mean that i have to write 32 function to be called from 32 group!, so i want everything to be simple if i could, also the (return) not work inside the button java script and it give me error (return only work in function), the main problem of the code that its warn me but it doesn't reset the check boxes,,, any help will be appreciated , thank you

     // Initialize counter

        // for First Trainer in First Page it will Start (A)

        var CurrentField = "A"

        var tarinee = getField("Trainer1");

        var sum = 0;

        var sum2 = getField("PeriodVar");

        var sum3 = sum2.value;

        // Loop through the check boxes

        for (var i = 1; i <= 20; i++) {

    

            // Increment counter if check box is selected

            if (getField(CurrentField+i).value !== "Off") sum++;

    

            // If more than sum3 are selected, deselect the one that was just selected,

            // alert the user, and return

           

   if (sum > sum3 ) {

                event.target.value = "Off";

                //Adding Asking if you want to delete all the marks

                var scal = "The Max Number for Attendance is "

                var scmsg = "Do you want to Remove Trainer marks? "

               //check if the trainer name exist first

                var tarineeName= tarinee.value;

                if (app.alert(scal+sum3+"\n"+"\n"+scmsg+""+tarineeName, 2,2)==4)

                for (var i=1;i<=20;i++)

            {

              this.resetForm(CurrentField+i);

            }

                //return;

}

}

Best
Mohammad Hasanin
TOPICS
Acrobat SDK and JavaScript , Windows

Views

495

Translate

Translate

Report

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

correct answers 1 Correct answer

Enthusiast , Apr 21, 2018 Apr 21, 2018

Hello Sir,, thank again for Inspiration me with the words (cannot get out of the loop), i refer to java script API Reference and found that i should use arrays for the resetForm Command to Run as Described Here.

var fields = new Array();

fields[0] = "P1.OrderForm.Description";

fields[1] = "P1.OrderForm.Qty";

this.resetForm(fields);

So I Decided to try the Looping for Inserting the All Check Boxes Inside the Array and it Works like Charm!

     // Initialize counter

        // for First Trainer in First

...

Votes

Translate

Translate
Community Expert ,
Apr 21, 2018 Apr 21, 2018

Copy link to clipboard

Copied

Are you getting an error message on the JavaScript console (Ctrl-J or Cmd-J)? If so, what exactly does it say?

I would run this from the calculation script of a hidden and read-only text field. From what I see, it should work, but there is one potential problem: When the user decides to not clear the marks, the popup gets triggered again, and unless you clear, you cannot get out of that loop.

Votes

Translate

Translate

Report

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
Enthusiast ,
Apr 21, 2018 Apr 21, 2018

Copy link to clipboard

Copied

Thank you sir for your reply,Sorry for being late i was so far from computer,  Actually the Problem is I must use Check Boxes inside the form So when The Trainer is coming to the particular day it will show (Right Sign) otherwise if he absent it will be Off (Empty Check Box) or (Boxes) if he as an Example absent in (Tuesday) and (Friday) ...etc , also i cant see any calculation script inside Checkbox Properties Window, and i want to add more explaining for what i do,, there are a Text Field have Numeric Value i Called it (Period Var) , it controls the amount of days, lets Suppose that the Course is Only 5 days, So the trainer will come only five days, the Above Code try to Prevent you from Check more days other than Written in Value inside (Period Var) so if the Course is 5 days and you check in the 6 days the Program will alert you that you make mistake and delete the last (Check) and also Ask you if you want to delete the all Trainer Check Marks (Checked Boxes),, the first part of the code are working well except the part of (if i Answer Yes) it will not delete my previous Checked Boxes,, the code was working very well inside the Document java script but the Idea i Want to Attach to checkbox so i can duplicate the page and alter the all code easily, i hope my ideas are clear now

Best
Mohammad Hasanin

Votes

Translate

Translate

Report

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
Enthusiast ,
Apr 21, 2018 Apr 21, 2018

Copy link to clipboard

Copied

LATEST

Hello Sir,, thank again for Inspiration me with the words (cannot get out of the loop), i refer to java script API Reference and found that i should use arrays for the resetForm Command to Run as Described Here.

var fields = new Array();

fields[0] = "P1.OrderForm.Description";

fields[1] = "P1.OrderForm.Qty";

this.resetForm(fields);

So I Decided to try the Looping for Inserting the All Check Boxes Inside the Array and it Works like Charm!

     // Initialize counter

        // for First Trainer in First Page it will Start (AA) - for Second Page it will start (AB)--etc..

        var CurrentField = "A"

        var tarinee = getField("Trainer1");

        var sum = 0;

        var sum2 = getField("PeriodVar");

        var sum3 = sum2.value;

        // Loop through the check boxes

        for (var i = 1; i <= 20; i++) {

  

            // Increment counter if check box is selected

            if (getField(CurrentField+i).value !== "Off") sum++;

  

            // If more than sum3 are selected, deselect the one that was just selected,

            // alert the user, and return

          

  if (sum > sum3 ) {

                event.target.value = "Off";

                //Adding Asking if you want to delete all the marks

                var scal = "The Max Number for Attendance is "

                var scmsg = "Do you want to Remove marks? "

              //check if the trainer name exist first

                var tarineeName= tarinee.value;

                if (app.alert(scal+sum3+"\n"+"\n"+scmsg+""+tarineeName, 2,2)==4)

                //for (var i=1;i<=20;i++)

            {

              var CurrentFieldArray= new Array();

              for (var i=1;i<=20;i++)

              CurrentFieldArray = "A"+i;

              this.resetForm(CurrentFieldArray);

            }

}

}

now the Code Prevent User from Checking more Marks other than (Period Var) and also Able to delete all the marks if Required (Answered Yes in Alert)

Best
Mohammad Hasanin

Votes

Translate

Translate

Report

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