I am dynamically setting the options of my select-fields. Every time the form changes, new data is received from a Servlet and the current selections are overwritten.
Problem here is, that if I select an option, the form loads the javascript function, and I loose my selection / focus.
var capacityOptionsAsString = "";
for(var i = 0; i < capacityArray.length; i++) {
capacityOptionsAsString += "<option value='" + capacityArray[i] + "'>" + capacityArray[i] + "</option>";
console.log('capacity option: ' + capacityOptionsAsString);
}
$("select[name='inptCapacity']").find('option').remove().end().append($(capacityOptionsAsString));
Any idea how to keep the selection?
Edit: Maybe I was not clear enough. I want to keep the selection. So it has to be validated, if the option is selected, if it is, we have to select it again.