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

Making Code More Simpler

Enthusiast ,
Apr 22, 2018 Apr 22, 2018

Copy link to clipboard

Copied

Hi Friends.

Now i found using the following code is more easy than Regular Reset Form for Particular Fields (16 Groups) of Checkboxes., this code working very well form any Button or Document javascript as function, but it really looks crazy!

function ClearComboBoxes()

{

//Remove CheckBoxes A

var CurrentFieldArray= new Array();

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

CurrentFieldArray = "A"+i;

this.resetForm(CurrentFieldArray);

//Remove CheckBoxes B

var CurrentFieldArray= new Array();

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

CurrentFieldArray = "B"+i;

this.resetForm(CurrentFieldArray);

//Remove CheckBoxes C

var CurrentFieldArray= new Array();

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

CurrentFieldArray = "C"+i;

this.resetForm(CurrentFieldArray);

//Remove CheckBoxes D

var CurrentFieldArray= new Array();

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

CurrentFieldArray = "D"+i;

this.resetForm(CurrentFieldArray);

//Remove CheckBoxes E

var CurrentFieldArray= new Array();

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

CurrentFieldArray = "E"+i;

this.resetForm(CurrentFieldArray);

//Remove CheckBoxes F

var CurrentFieldArray= new Array();

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

CurrentFieldArray = "F"+i;

this.resetForm(CurrentFieldArray);

//Remove CheckBoxes G

var CurrentFieldArray= new Array();

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

CurrentFieldArray = "G"+i;

this.resetForm(CurrentFieldArray);

//Remove CheckBoxes H

var CurrentFieldArray= new Array();

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

CurrentFieldArray = "H"+i;

this.resetForm(CurrentFieldArray);

//Remove CheckBoxes I

var CurrentFieldArray= new Array();

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

CurrentFieldArray = "I"+i;

this.resetForm(CurrentFieldArray);

//Remove CheckBoxes J

var CurrentFieldArray= new Array();

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

CurrentFieldArray = "J"+i;

this.resetForm(CurrentFieldArray);

//Remove CheckBoxes K

var CurrentFieldArray= new Array();

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

CurrentFieldArray = "K"+i;

this.resetForm(CurrentFieldArray);

//Remove CheckBoxes L

var CurrentFieldArray= new Array();

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

CurrentFieldArray = "L"+i;

this.resetForm(CurrentFieldArray);

//Remove CheckBoxes M

var CurrentFieldArray= new Array();

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

CurrentFieldArray = "M"+i;

this.resetForm(CurrentFieldArray);

//Remove CheckBoxes N

var CurrentFieldArray= new Array();

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

CurrentFieldArray = "N"+i;

this.resetForm(CurrentFieldArray);

//Remove CheckBoxes O

var CurrentFieldArray= new Array();

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

CurrentFieldArray = "O"+i;

this.resetForm(CurrentFieldArray);

//Remove CheckBoxes P

var CurrentFieldArray= new Array();

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

CurrentFieldArray = "P"+i;

this.resetForm(CurrentFieldArray);

}

Here is my Approach  to make it More Simple by nesting the loops inside the Array (16 Groups, Every Group have 20 Check boxes) but with no success, the JavaScript Debugger always Shown Error (Undefined) but when putting this inside button in run-time no error shown, any help is appreciated, thanks in advance.

var CurrentFieldArray = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P"];

for (var cf=0; cf<CurrentFieldArray.length; cf++) {

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

CurrentFieldArray[cf].valueAsString = CurrentFieldArray[cf].valueAsString+xx.value;

this.resetForm(CurrentFieldArray);

{

        break;

    }

}

}

Best
Mohammad Hasanin
TOPICS
Acrobat SDK and JavaScript , Windows

Views

798

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 22, 2018 Apr 22, 2018

i found the solution ! and remove many unwanted lines!

var Arr= ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P"];

for (var cfm=0; cfm<Arr.length; cfm++) {

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

              this.getField(Arr[cfm]+x).value = "" ;

            }

    }

also line Number 4 can be altered by and it will do the job!

this.resetForm(Arr[cfm]+x);

But i found that using  

 this.getField(Arr[cfm]+x).value = "" ;

execute much faster than the (resetForm)

Votes

Translate

Translate
Community Expert ,
Apr 22, 2018 Apr 22, 2018

Copy link to clipboard

Copied

You're on the right path... One thing that's important to know is that "undefined" is not an error. Quite the opposite.

It just means that the script completed running without throwing any errors or returning any values.

I won't give you the correct code to do it, but will guide you in solving the issues you have.

First of all, you need to think very carefully about each command in your code. Why did you add it? What does it do? Is it necessary?

Also, you need to think about the types of variables you have. How do you access their values? What properties and methods do they have? etc.

And, of course, try to debug your code. Add console.println commands so you could see the values of your variables while the code is running and follow what is going on with it.

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 22, 2018 Apr 22, 2018

Copy link to clipboard

Copied

ok i will try hard and let you know

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 22, 2018 Apr 22, 2018

Copy link to clipboard

Copied

i found the solution ! and remove many unwanted lines!

var Arr= ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P"];

for (var cfm=0; cfm<Arr.length; cfm++) {

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

              this.getField(Arr[cfm]+x).value = "" ;

            }

    }

also line Number 4 can be altered by and it will do the job!

this.resetForm(Arr[cfm]+x);

But i found that using  

 this.getField(Arr[cfm]+x).value = "" ;

execute much faster than the (resetForm)

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
Community Expert ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

Well done!

If you want to use the resetForm command you should collect all the field names into a single array and then call it once, instead of calling it for each field, which is indeed slower.

One important thing to understand about this command, though, is that it doesn't clear the values of the fields. It reverts them to their default value, which is not (necessarily) the same as a blank value.

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 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

Thank you for your Valuable Recommendations and Explanation of the Nature of JavaScript

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
Engaged ,
Apr 30, 2018 Apr 30, 2018

Copy link to clipboard

Copied

When cycling through all the elements of an array, you can use the "in" keyword.  It prevents from having to create a variable for your loop

for (i in CurrentFieldArray) { 

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

CurrentFieldArray.valueAsString = CurrentFieldArray.valueAsString+xx.value; 

this.resetForm(CurrentFieldArray); 

break; 

}

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 ,
May 03, 2018 May 03, 2018

Copy link to clipboard

Copied

I Try it but not working!

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
Engaged ,
May 03, 2018 May 03, 2018

Copy link to clipboard

Copied

What is not working?

Of course, tthe script I copied from your post will not work, but the loop part will.

So for the solution you say did work, replace this:

for (var cfm=0; cfm<Arr.length; cfm++)

with this:

for (cfm in Arr)

Also, I figure your fields are named A1, A2, A3 ......all de way to P20.  Next time, try to name them in a parent/child way  --->   A.1 , A.2, A.3, etc.  That way, instead of having to loop throught all letters and all numbers, you can apply an action on the parent field and all child will be affected.

A simple this.resetForm(["A"]) would have taken car of all 20 child fields of "A"

  1. var Arr= ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P"]; 
  2. this.resetForm(Arr) 

these 2 simple lines would have taken care of all 16 * 20 fields because when you enter only one command in a loop, you do not need to but it inside brackets {}.  Since resetForm() takes an array of fields names as an argument, you can pass Arr to it directly.

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 ,
May 06, 2018 May 06, 2018

Copy link to clipboard

Copied

LATEST

Thank you, i think shortening the code affect its execution speed, i learned that before while developing in multimedia applications

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