# Dynamically refresh date when PopupMenu selection changes

I am trying to adapt the following snippet to behave in such a way that when a new selection is made - even if there is no change, then the date time stamp updates, I would also like to grab the user profile name from computer and append it to the date with every change. The purpose of which is to ascertain from which computer login was the selection made from.

(*user defined levels and associated colors*)
levels = {"Self Assess", "Mastery", "Dominance", "Proficeincy",
"Fuzzy"};
levelColors = {White, Green, Yellow, Red, Gray};

DynamicModule[{x = levels[[1]]},
Row[{PopupMenu[Dynamic[x], levels,
Background -> Dynamic[
Which[
x === levels[[1]], levelColors[[1]],
x === levels[[2]], levelColors[[2]],
x === levels[[3]], levelColors[[3]],
True, levelColors[[4]]]]],
DateString[]}]]


I tried Refresh, Dynamic@Row, TrackedValue, and even ValueFunction to no avail. Any Thoughts?

## 1 Answer

Not an expert (so you might want to wait for some more input from others), something like this works for me (assuming this is what you have in mind).

The idea is to use the second argument to Dynamic to update the date, which (here) is stored in t:

(*user defined levels and associated colors*)
levels = {"Self Assess", "Mastery", "Dominance", "Proficeincy",
"Fuzzy"};
levelColors = {White, Green, Yellow, Red, Gray};

DynamicModule[
{x = levels[[1]],
t = DateString[]},
Row[{
PopupMenu[
Dynamic[x, (x = #; t = DateString[]) &],
levels,
Background -> Dynamic[
First@Pick[
levelColors,
levels,
x
]
]
],
Dynamic[t],
SystemInformation["FrontEnd", "UserName"]
},
Spacer[5]
]
]

• This is definitely usable. Thank you so much for your time. Dec 4 '17 at 21:50
• No problem, glad it ended up being helpful!
– Anne
Dec 4 '17 at 21:58