Skip to main content
Inspiring
Oct 28, 2018 8:30 AM UTC
Answered

run loop only one time

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 is closed to new replies. Start a new post to keep the conversation going.
subieguy2
subieguy2Correct answer
Inspiring
Nov 12, 2018 11:46 AM UTC

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.

6 replies

hackertomAuthor
Inspiring
Oct 28, 2018 2:49 PM UTC

any example about that?

Translate
subieguy2
Inspiring
Nov 8, 2018 6:11 PM UTC

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

}

Translate
hackertomAuthor
Inspiring
Nov 10, 2018 9:22 AM UTC

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.

Translate
try67
Community Expert
Community Expert
Oct 28, 2018 9:19 AM UTC

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.

Translate