10 examples of 'how to set select option value dynamically in jquery' in JavaScript

Every line of 'how to set select option value dynamically in jquery' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
53export async function selectOption(value: string, selectField: ElementFinder): Promise<void> {
54 return selectField.$(`option[value="${value}"`).click();
55}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

191function addSelectOption(optionId, disabled) {
192
193 // add an <option> to the <select>
194 // used only by buildSelect()
195
196 if(disabled == undefined) var disabled = false;
197
198 var $O = $('#' + optionId);
199 var $option = $("<option>" + $O.text() + "</option>")
200 .val($O.val())
201 .attr('rel', optionId);
202
203 if(disabled) disableSelectOption($option);
204
205 $select.append($option);
206}
191function addSelectOption(optionId, disabled) {
192
193 // add an <option> to the <select>
194 // used only by buildSelect()
195
196 if(disabled == undefined) var disabled = false;
197
198 var jQueryO = jQuery('#' + optionId);
199 var jQueryoption = jQuery("<option>" + jQueryO.text() + "</option>")
200 .val(jQueryO.val())
201 .attr('rel', optionId);
202
203 if(disabled) disableSelectOption(jQueryoption);
204
205 jQueryselect.append(jQueryoption);
206}
255private updateDom_select(element: JQuery<HTMLElement>, value: any) {
256 element.val(value);
257}
54updateOption(value, args) {
55 const option = document.querySelector(`option[value=${value}]`);
56 option && Object.assign(option, args);
57}
207private setSingleSelectedOption(option: SelectItem | undefined) {
208 const previous = this.selectedItems.length > 0 ? this.optionsMap[this.selectedItems[0].value] : undefined;
209 this.selected = option ? this.optionsMap[option.value] : undefined;
210 return previous;
211}
229function enableSelectOption($option) {
230
231 // given an already disabled select option, enable it
232
233 $option.removeClass(options.optionDisabledClass)
234 .attr("disabled", false);
235
236 if(options.hideWhenAdded) $option.show();
237 if($.browser.msie) $select.hide().show(); // this forces IE to update display
238}
81function selectCallback(value, index) {
82 $(".demo .callback_output").prepend("<p>VALUE: " + value + ", INDEX: " + index + "</p>");
83}
47function onChangeSelect(option) {
48 setValue(option.value)
49}
69function setDropdownValue(event) {
70 var dt = event.target.parentNode.parentNode.previousSibling;
71 dt.value = event.target.getAttribute("value");
72 dt.firstChild.textContent = event.target.textContent;
73
74 dt.parentNode.setAttribute("dropped", "false");
75
76 var evt = document.createEvent("HTMLEvents");
77 evt.initEvent("change", true, true);
78 dt.dispatchEvent(evt);
79}

Related snippets