I have used the select2.js
library for dropdown list in my code. I want to select the dropdown value deafult as per the value get from my url. I have no idea how to do that thing in select.js
.
Here in below code var e
I get the value which I want to selected.
Javascript code:
$( document ).ready(function() {
var url = window.location.href;
var a = url.split('=');
var b = a[2];
var d = b.split('_');
var e =d[1];
$("#Address1").select2({
})
});
HTML code:
<select class="ct-select-lg" id="Address" name="Address[]">
</select>
In these code i get the data from my API:
$("#Address").select2({
ajax: {
url: "url",
dataType: 'json',
delay: 250,
data: function (params) {
return {
q: params.term,
page: params.page
};
},
processResults: function (data, params) {
return {
results: data.items,
};
},
cache: true
},
placeholder: 'Search for a repository',
escapeMarkup: function (markup) { return markup; },
minimumInputLength: 1,
});