Skip to main content
Inspiring
October 28, 2018
Answered

run loop only one time

  • October 28, 2018
  • 2 replies
  • 832 views

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 ??

This topic has been closed for replies.
Correct answer subieguy2

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.


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.

2 replies

hackertomAuthor
Inspiring
October 28, 2018

any example about that?

subieguy2
Inspiring
November 8, 2018

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++;

}

hackertomAuthor
Inspiring
November 10, 2018

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.

try67
Community Expert
Community Expert
October 28, 2018

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.