I am trying create a dialog window for updating a variable number of parameters $\beta_i$. Here are the relevant bits of my code, which first constructs a list of $\beta_i$ parameters, then constructs the dialog box based on the number of parameters that I specify, and then executes the dialog box.

AppendTo[testgrid, {CancelButton[],DefaultButton[DialogReturn[]]}];

When I run this code, the dialog box pops up just fine, but the "params" list of parameters is not getting updated. I am guessing that my mistake has something to do with not directly putting the parameter in the InputField.


1 Answer 1


You need Dynamic around the symbol inside of InputField

nparams = 3;
params = Table[Symbol["B" <> ToString[x]], {x, 1, nparams}];
testgrid = {};
For[n = 1, n <= nparams, n++, row = {StringJoin["B", ToString[n]],
   InputField[Dynamic[Evaluate@params[[n]]], Expression]}; AppendTo[testgrid, row]]
AppendTo[testgrid, {CancelButton[], DefaultButton[DialogReturn[]]}];
CreateDialog[Grid[testgrid, Spacings -> {1, Automatic}, Alignment -> Left], Modal -> True]

If the code needs to work after the values are set for the first time, you can apply this modification:

params = Table["B" <> ToString[x], {x, 1, nparams}];
testgrid = {};
For[n = 1, n <= nparams, n++, row = {StringJoin["B", ToString[n]],
  ToExpression["InputField[Dynamic[" <> params[[n]] <> "],Expression]"]};
  AppendTo[testgrid, row]]
  • $\begingroup$ Thanks! I had attempted using the Dynamic command, but didn't have the Evaluate@ so it wasn't working. This looks like it will do the trick. $\endgroup$
    – ahle6481
    Commented Feb 24, 2016 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.