Skip to main content
Inspiring
November 8, 2018
Answered

for loop syntax with two tables?

  • November 8, 2018
  • 8 replies
  • 820 views

it is possible to write something like this and work?

var fields = ["Dropdown14.0","Dropdown14.1","Dropdown14.2"];

var fields1 = ["Text1","Text2","Text3"];

for (var i in fields && i1 in fields1)

{

    var f = this.getField(fields);

    var f1 = this.getField(fields1[i1]);

    if (f.valueAsString!=1==false && f1.valueAsString!=2==false) total++;

}

i now the syntax "for in" check only one table at the time... it is possible to check 2? because now this not work...

This topic has been closed for replies.
Correct answer try67

You can do it like this:

for (var i=0; i<fields.length; i++)  {

    var f = this.getField(fields);

    var f1 = this.getField(fields1);

    if ( ... ) total++;

}

Of course, the length of the two arrays has to be the same for it to work.

PS. Your if-condition is incorrect I so removed it from the code.

What exactly are you trying to check?

8 replies

hackertomAuthor
Inspiring
November 10, 2018

correct answer try67 now i understand your code...

hackertomAuthor
Inspiring
November 8, 2018

i want to check all 6 cells

"Dropdown14.0" --> "Text1"

"Dropdown14.1" --> "Text2"

"Dropdown14.1" --> "Text3"

now I thought if loop check cell position 1 for fields=1 & fields1=2 then totall++

var f = this.getField(fields.rows[0].cells.length);

var f1 = this.getField(fields1.rows[0].cells.length);

and if I work I'm going to the other below.... this is error;

try67
Community Expert
Community Expert
November 8, 2018

The code I provided will do that. You can't just invent syntax and hope it to work.

Legend
November 8, 2018

If you only want one element, just don't use a loop.

hackertomAuthor
Inspiring
November 8, 2018

yes you has right, my mistake remove this "Dropdown14.0" is 1 and "Text2" is 2 then NO COUNT

I wrote some possible examples..

this examples is count++ only if one is deferent then NO COUNT :

"Dropdown14.0" is 1 and "Text1" is 2 then total++

"Dropdown14.1" is 1 and "Text2" is 2 then total++

"Dropdown14.2" is 1 and "Text3" is 2 then total++

and I have another question, if i replace 2 with regular expression how to write on code? this is correct?

var fields = ["Dropdown14.0","Dropdown14.1","Dropdown14.2"];

var fields1 = ["Text1","Text2","Text3"];

var myRegExpadt = /^.*?(\B[A-Z.]{1,2}[0-9]{6}\b).*NAME:\ [A-Z]+.*$/;

for (var i=0; i<fields.length; i++)  {

    var f = this.getField(fields);

    var f1 = this.getField(fields1);

    if (f.valueAsString!="1"==false && myRegExpadt.test(f1.valueAsString)==false) total++;

}

try67
Community Expert
Community Expert
November 8, 2018

I don't understand why you're trying to use a RegExp for... It's better to walk before starting to run.

Your condition can be:

if (f.valueAsString=="1" && f1.valueAsString=="2") total++;

hackertomAuthor
Inspiring
November 8, 2018

i try this code and work, but has a problem : first Text field  must have 2 and then  dropdown list number 1 to count total++

if i choose first dropdown list number 1 and them write on text field 2 then no count...

My RegEx help me to check a code :  \B[A-Z.]{1,2}[0-9]{6}\b  and a name :.*NAME:\ [A-Z]+.*$

if this is true and dropdown list is 1 then only count, i replace RegEx with 2 for more easy example...

this is correct?

if (f.valueAsString=="1" && myRegExpadt.test(f1.valueAsString)==true) total++;

hackertomAuthor
Inspiring
November 8, 2018

What do you mean? Its not possible to create this?

try67
Community Expert
Community Expert
November 8, 2018

It's logically contradictory:

"Dropdown14.0" is 1 and "Text1" is 2 then total++

"Dropdown14.0" is 1 and "Text2" is 2 then NO COUNT

hackertomAuthor
Inspiring
November 8, 2018

my thought is when only

"Dropdown14.0" is 1 and "Text1" is 2 then total++

"Dropdown14.1" is 1 and "Text2" is 2 then total++

"Dropdown14.2" is 1 and "Text3" is 2 then total++

but when e.g.:

"Dropdown14.0" is 1 and "Text2" is 2 then NO COUNT

or "Dropdown14.1" is 1 and "Text1" is 2 then NO COUNT

or "Dropdown14.2" is 1 and "Text3" is 2 then NO COUNT

or "Dropdown14.1" is 1 and "Text3" is 2 then NO COUNT

or "Dropdown14.0" is 1 and "Text2" is 2 then NO COUNT

.

.

.

try67
Community Expert
Community Expert
November 8, 2018

The first two conditions are contradictory.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
November 8, 2018

You can do it like this:

for (var i=0; i<fields.length; i++)  {

    var f = this.getField(fields);

    var f1 = this.getField(fields1);

    if ( ... ) total++;

}

Of course, the length of the two arrays has to be the same for it to work.

PS. Your if-condition is incorrect I so removed it from the code.

What exactly are you trying to check?

Bernd Alheit
Community Expert
Community Expert
November 8, 2018

What want you count?