Here is what I am trying to do:
- I am getting a value from PHP and putting it in a textbox (function 1). That works fine.
- I am trying to use that value in another PHP query (function 2). Does not work fine.
Both functions should start on loading the page and must remain in separate functions. Problem: the result variable of the first function cannot be found in the second one. As I tried to point out inside the code, the variable "seizoen" remains empty in the second function. Any idea what I am doing wrong here or how I can solve this?
<input type="text" id="Seizoen_text" OnChange="getCompetitie()>
<select id="Competitie_list"></select>
window.onload = function() {
getSeizoen();
getCompetitie();
};
function getSeizoen() {
$.ajax({
type:'POST',
url:'get_seizoen.inc.php',
dataType: 'json',
success: function(response){
var maxseizoen = response[0]['MaxSeizoen'];
$("#Seizoen_text").val(maxseizoen);
}
});
}
function getCompetitie() {
seizoen = $("#Seizoen_text").val();
alert(seizoen); // **--> EMPTY !**
$.ajax({
type:'POST',
url:'get_competitie.inc.php',
dataType: 'json',
data: {seizoen: seizoen},
success: function(response){
$("#Competitie_list").empty();
var len = response.length;
for(var i = 0; i < len; i++){
var competitievorm = response[i]['Competitie'];
$("#Competitie_list").append("<option value='"+competitievorm+"'>"+competitievorm+"</option>");
}
}
});
}