Reputation: 29
Hi there i am using the select2-plugin in a search:
$(document).ready(function () {
$('#dropdown_users').select2({
placeholder: 'Search for a category',
ajax: {
url: "search.php",
dataType: 'json',
quietMillis: 100,
data: function (term, page) {
return {
term: term, //search term
page_limit: 10 // page size
};
},
results: function (data, page) {
return { results: data.results };
}
},
initSelection: function(element, callback) {
return $.getJSON("search?id=" + (element.val()), null, function(data) {
return callback(data);
});
}
});
});
My question is: When user select´s an option from the select, the selected data should be saved in a variable, like:
.onSelect: function() {
var variable = $_GET['data'];
}
Is this possible?? Greetings!!
Upvotes: 0
Views: 158
Reputation: 10714
$("#dropdown_users").on("select2-selecting", function(e) {
variable = e.val;
})
Note that this has been included in the 3.4 version.
Upvotes: 1