Select Dropdown item with js

Problem: I have a dropdown box which is populated using the following javascript:

function addItem(dropdown, item) {
dropdown.append(<option value="${item}">${item}</option>);
}
var dropdown = $(‘select’, prez.object(“Dropdown_251”).node);

dropdown.empty();
addItem(dropdown, “–Select Student–”);

for (i = 0; i < Array_1.length; i++) {
addItem(dropdown, Array_1[i]);
}

This all works fine but I would also like to have an item preselected using javascript based on the value of a variable but I can’t find a way to do it.

ActivePresenter version: 9.3.0

OS: win 11

Notes:

@scottjones05- Give this a try

prez.object("Dropdown_Name").value("Desired Value"); 

Change the name of your dropdown and the value that you have predefined to show.

You could place this as an on Enter action or as an action for some other event.

Hope this helps.

EDIT:

Reading the post again - I see you wanted to do this based on a variable…
Therefore - change as below - replace variable_Name with the name of your associcated variable.

prez.object("Dropdown_Name").value(prez.variable("variable_Name"));
1 Like

Thanks for this, worked exactly as I wanted.