Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can use the addChoice method provided by Choices.js to programmatically add options to the select menu. Here's an example:

const choices = new Choices('#my-select');
choices.addChoice({
  value: 'option-value',
  label: 'Option Label',
  selected: true
});

In this example, the addChoice method adds a new option to the select menu with the value "option-value", label "Option Label", and the selected property set to true. This will ensure that the option remains selected even if the user clicks away from the menu and comes back later.