I’m using Select2 Dropdown library
On tag dropdown there is select2 on ajax is applied
$('#sug_cstm_tag').select2({ ajax: {
url: base_url+'index.php',
dataType: 'json',
delay: 250, //wait for 250 milliseconds for another trigger
data: function (params) {
var query = {
entryPoint:'restapi',
module:'vaidam',
action:'newtags',
search: params.term,
type:'include_id'
}
return query;
}
},
placeholder: 'Search Tags',
minimumInputLength: 2,
allowClear: true,width: "140px"
});
Above code manipulate select options with sug_cstm_tag
ID
What I require is on Click an external button to update the selected option value.
Which is easily applied on normal select2 initialization
e.g. $('#sug_cstm_tag').select2();
value change $('#sug_cstm_tag').val('fibroids').trigger('change');
add comment
1 Answer
Found The Solution
First create Option Object with values
Then append it to select option and trigger change
var option = new Option(tag_text_value, tag_id, true, true);
studentSelect.append(option).trigger('change');
share
add comment
Your Answer
asked | |
viewed | 17 |
Related
- 1How to add a key/value pair to an object JavaScript?
- 1How to update parent state from child component in React?
- 1How to detect a click event outside a DOM element?
- 2Retrieve json object value from input text field using javascript
- 1setState doesn't update the state immediately
- 2How can you reliably test if a value is equal to NaN?
- 1How can i write update query in SQL
- 1How to update a specific dev dependency with composer
- 1How to compare two arrays, and return the name of the array with highest value in a certain index
- 2slideup and slidedown div on click button?
- 1How to iterate over the return value of Promise.all() ?