Sure enough, the selected option is displayed via the console log; once as the value of
find.('option:selected').text()
and again as the value of
state.active.variables.chosen_pie
But the <div> is not updated.
I want to update the #pie div with the value of the chosen pie.
So
I don’t really understand when <<done>> runs. It runs when the page has initially been rendered, but it seems to run when new options are selected from the list box. Where could I read about that behaviour? (and apologies it its in the docs - I couldn’t see it there, or didn’t understand what was there - more likely!)
How can I get the <<replace>> macro to run, with the value of state.active.variables.chosen_pie (or ??equivalently??) $chosen_pie.
<<done>> only runs once, immediately after the passage has been rendered. What’s running every time the listbox is changed is the event handler you defined inside the <<done>> macro. All you need to do is to is have that function also update the <div>.
<<done>> executes once. You’re seeing the firing of change event, which occurs each time the listbox is changed.
It’s not working because the change event handler you’re attaching is asynchronous. The <<replace>> is executed once as part of the <<done>>. You need to place the <div#pie> update within the change event handler.
<<done>>
<<script>>
$('#listbox-pie').on('change', function () {
$('#pie').text(State.variables.chosen_pie);
});
<</script>>
<</done>>
Doesn’t have the $(this).find('option:selected').text(). Should I expect to see the chosen value in $chosen-pie (the receiver var of the list box) without needing the $(this).find('option:selected').text() code?