# help with dynamic input

I'm trying to build a pop up window with i lines. Each line would read:

Number of neurons in layer 1:
Number of neurons in layer 2:
etc until layer i

The user would enter a numeric value on each line. That value would be recorded as d[1],d[2],...,d[i].

The solution I've come up with results in Mathematica assigning the input from any line to d[i] (for example if there are 5 lines, it assign inputs from line 1, 2..5 all to d[5]). I understand why it's happening. I just can't think of how I'm suppose to achieve what I want.

Here's my code:

a = Table[
List[StringJoin[{"Number of neurons in layer ", ToString[i], ":"}],
InputField[Dynamic[d[i]], Number]], {i, 3}];
AppendTo[a, {CancelButton[], DefaultButton[DialogReturn[]]}];
CreateDialog[Grid[a, Spacings -> {1, Automatic}, Alignment -> Left], Modal -> True];


Any suggestions? Thanks.

-
Welcome to Mathematica.SE Omid! I formatted your code for you; here is a guide that shows how you can do this yourself on future posts. Also, please consider registering your account so that any upvotes you get on this question are added to those you might get on future questions and answers. That way, over time you will be able to do more on the site (post graphics, edit things, etc). – Verbeia Aug 28 '12 at 23:01
@Omid welcome to MMA.SE. You need to change the first argument (List[...]) in Table to With[{i=i},List[...]]. Pls check this answer to a related question. – kglr Aug 28 '12 at 23:20

Simple fix. Put With[{i=i}] to get the indexing in the dynamic right:

a = Table[List[
StringJoin[{"Number of neurons in layer ", ToString[i], ":"}],
With[{i = i}, InputField[Dynamic[d[i]], Number]]], {i, 3}];
AppendTo[a, {CancelButton[], DefaultButton[DialogReturn[]]}];

CreateDialog[Grid[a, Spacings -> {1, Automatic}, Alignment -> Left], Modal -> True];


On a sidenote, When I paste your code into Mathematica the i in InputField[Dynamic[d[i]], Number] turns red. If you highlight such a red character and go to the menu "help/why the coloring" it actually tells you that the order of evaluation conflicts.

I have added some more details on why this problem occurs, and why the solution works to a previous related question: Generating dynamic Inputfields

-