You want to use the select element's onchange event, in which you can get the value of the selected item and then save that. The selected index is in the element's selectedIndex property, which you can use to look up the value in its options array. Try this:
var selectElement = document.getElementById("test");
selectElement.addEventListener("change", function (evt) {
var select = evt.target;
if (select.selectedIndex >= 0) {
roamingSettings.values["test"] = select.options[select.selectedIndex].value;
}
});
To initialize the control, just do the reverse (inside the check for the existence of your settings, of course), but because you're saving a value you need to iterate through the select element's options collection to find it:
var selectedItem = roamingSettings.values["test"];
var options = selectElement.options;
var selectedIndex = null;
for (var i = 0; i < options.length; i++) {
if (selectElement.options.item(i).value == selectedItem) {
selectedIndex = i;
break;
}
}
if (null != selectedIndex) {
selectElement.selectedIndex = selectedIndex;
}