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

run loop only one time

Explorer ,
Oct 28, 2018 Oct 28, 2018

Copy link to clipboard

Copied

hello, i use this on Text field :

event.value = event.value.replace(/\,AbAb/g, "1234");

program check if AbAb and replace it with 1234

how to run only one time this loop? and if i write again AbAb the keep AbAb ??

TOPICS
Acrobat SDK and JavaScript

Views

249

Likes

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

Engaged , Nov 12, 2018 Nov 12, 2018

Ok so if you want the loop to run more times then change the length like this....

var check = 0; 

 

if (check < 4){ 

event.value = event.value.replace(/\,AbAb/g, "1234"); 

check++; 

}

Or depending on how and where you are running this from do like Bernd Alheit​ said and check multiples like this...

var checkFieldOne = 0; 

var checkFieldTwo = 0;

var checkFieldThree = 0;

var checkFieldFour = 0;

var checkFieldFive = 0;

 

if (checkFieldOne == 0){ 

event.value = event.value.replace(/\,AbAb/g, "1234"); 

chec

...

Likes

Translate

Translate
Community Expert ,
Oct 28, 2018 Oct 28, 2018

Copy link to clipboard

Copied

It's not possible within that code itself. You will need to keep some kind of external marker for when it should (or shouldn't) replace that string.

Likes

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
Explorer ,
Oct 28, 2018 Oct 28, 2018

Copy link to clipboard

Copied

any example about that?

Likes

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 ,
Nov 08, 2018 Nov 08, 2018

Copy link to clipboard

Copied

Not sure if this will help you but.... maybe something like this??...

I guess it depends on where/how you run your script.

var check = 0;

if (check == 0){

event.value = event.value.replace(/\,AbAb/g, "1234");

check++;

}

Likes

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
Explorer ,
Nov 10, 2018 Nov 10, 2018

Copy link to clipboard

Copied

hi subieguy2 this answer work for 1 field...

i have 5 text fields and i want to restart this loop for every new field... for now on text field 1 work but when i go to text field 2 not work because check has value 1.

Likes

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 ,
Nov 10, 2018 Nov 10, 2018

Copy link to clipboard

Copied

Use check1, check2, and so on for the fields.

Likes

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 ,
Nov 12, 2018 Nov 12, 2018

Copy link to clipboard

Copied

LATEST

Ok so if you want the loop to run more times then change the length like this....

var check = 0; 

 

if (check < 4){ 

event.value = event.value.replace(/\,AbAb/g, "1234"); 

check++; 

}

Or depending on how and where you are running this from do like Bernd Alheit​ said and check multiples like this...

var checkFieldOne = 0; 

var checkFieldTwo = 0;

var checkFieldThree = 0;

var checkFieldFour = 0;

var checkFieldFive = 0;

 

if (checkFieldOne == 0){ 

event.value = event.value.replace(/\,AbAb/g, "1234"); 

checkFieldOne++; 

}

if (checkFieldTwo == 0){ 

event.value = event.value.replace(/\,AbAb/g, "1234"); 

checkFieldTwo++; 

}

if (checkFieldThree == 0){ 

event.value = event.value.replace(/\,AbAb/g, "1234"); 

checkFieldThree++; 

}

if (checkFieldFour == 0){ 

event.value = event.value.replace(/\,AbAb/g, "1234"); 

checkFieldFour++; 

}

if (checkFieldFive == 0){ 

event.value = event.value.replace(/\,AbAb/g, "1234"); 

checkFieldFive++; 

}

If this doesn't get you what you are looking for I would suggest posting more details about your document and how you want it to be used. Or better yet share a file and we can help try to get your questions answered.

Likes

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