Using a prompt to set options

I am creating a toolbar. One of the buttons on my toolbar is this setcounter button below.

setcounter = Dynamic[Button[“Set Counters”, {

CounterAssignments -> {{“StaticChapter”, 3}, {“StaticSection”,

Appearance -> “Palette”]]

As shown, this button sets each counter to 3 and 5 respectively. I would like to create a prompt in the form of a popup window or dialog that will allow the user to enter their own positive integers. And then the option be set based upon those numbers.

I know I probably just need one line of code before “SetOptions…” but I can’t seem to get anything to work. I’ve tried dialogs… but I can’t get it to wait for the inputs before setting the option. Any Ideas?



1 Answer


DynamicModule[{counters, oldcounters},

Button[“Set Counters”,
oldcounters =
CurrentValue[InputNotebook[], {CounterAssignments}][[All, 2]];

counters = DialogInput[{x = 0, y = 0},
Row[{“StaticChapter “, InputField[Dynamic[x,(x = Round[#]) &], Number]}],
Row[{“StaticSection “, InputField[Dynamic[y,(y = Round[#]) &], Number]}],
Button[“Reset”, DialogReturn[{x, y}], ImageSize -> Automatic]}]
If[counters =!= $Failed && counters =!= $Canceled,
CounterAssignments -> {{“StaticChapter”,
counters[[1]]}, {“StaticSection”, counters[[2]]}}],

CounterAssignments -> {{“StaticChapter”,
oldcounters[[1]]}, {“StaticSection”, oldcounters[[2]]}}]
], Appearance -> “Palette”, Method -> “Queued”]



Thank you Mike. This works great! I was thinking their would be a simpler solution but based upon what you’ve done maybe not?
– Michael McCain
Dec 24 ’15 at 2:39



Spoke to soon…. Something isn’t working with your code. If I try calling one of the counterboxs it doesn’t work. I’m thinking it might be because your counters are stored as string and not numbers?
– Michael McCain
Dec 24 ’15 at 2:41



Yep! Change both occurrences of String to Number in your code and it works perfect! Thank you!
– Michael McCain
Dec 24 ’15 at 2:45



@MichaelMcCain yes correct. Also you need integers so I added a bit more to ensure that.
– Mike Honeychurch
Dec 24 ’15 at 3:41