# How to compare the InputField values in For loop dynamically

I am using a For loop for printing five InputFields. The loop gets its values from the variable tx. I want to compare the values dynamically with 10 and print the result. But, the comparison is going out of loop, why?

tx = {4, 1, 6, 7, 8};
Reap[For[i = 1, i <= 5, i++,
Sow[ {InputField[tx[[i]]],Dynamic[If[(tx[[i]] < 10), "right", "wrong"]]}]]]

-

This can be fixed by using With on the index. Also you missed a Dynamic in the inputfield:

 tx = {4, 1, 6, 7, 8};

yourLoop=Reap[For[i = 1, i <= 5, i++,
With[{i = i},
Sow[{
InputField[Dynamic[tx[[i]]]],
Dynamic[If[(tx[[i]] < 10), "right", "wrong"]]
}]
]
]];

yourLoop[[2, 1]] // Grid //Panel


There's some more details about the With[{i=i}] solution in my answer to the question Generating dynamic Inputfields

-

I do not know now how to automate the InputField using an index. But why not simply write them down? There are only 5 of them?

Here is an example using 2 InputFields

tx = {1, 2};
Grid[{
{InputField[Dynamic[tx[[1]]], Number, ContinuousAction -> True],
Dynamic[If[tx[[1]] < 10, "right", "wrong", "huh?"]]},

{InputField[Dynamic[tx[[2]]], Number, ContinuousAction -> True],
Dynamic[If[tx[[2]] < 10, "right", "wrong", "huh?"]]}

}, Frame -> True]


If I find a way to use a Table or such, will update, but it did not work when I tried it.

-