skip to Main Content

Set the value of select html element with multiple attribute programmatically

Context <!--HTML--> <select class="form-select mb-1" id="document-select" name="documents" multiple size="10"> <option class="document-option" value="1">20230308-seed-document-0</option> <option class="document-option" value="2">20230308-seed-document-1</option> // JS const documentSelectEl = document.getElementById("document-select"); form.addEventListener("submit", (event) => { documentSelectEl.selectedIndex = -1; documentSelectEl.value = ["1", "2"]; console.log(documentSelectEl.value); // Empty string documentSelectEl.value = "1,2"; console.log(documentSelectEl.value);…

VIEW QUESTION
Back To Top
Search