I have a <select> that gets populated from the database:
$(function(){
$.ajax({
type: "GET",
url: "lib/deleteuser.getusernames.php",
async: "false",
success: function(response){
$("#users").append('<option>' + response.split(",").join("</option><option>") + '</option>');
}
});
});
(this works fine by the way)
Now, I’m trying to take the value of the <select> and use it to run another query, but all that gets returned is nothing, or ‘undefined’.
Here’s what I have tried:
var username = $("#users option:selected").val();
var username = $("#users :selected").val();
var username = $("#users option:selected").text();
var username = $("#users :selected").text();
I understand that .val() only gets the value of an input, but in this case does the option text still count as input? I tried .text() just in case, but still came up with nothing.
It seems you are trying to get the value of the inputs before the ajax is complete, you should change
async: "false",toasync: false.