I trying to put multiple functions in same form with ajax.The form are used to prenote a new "meeting": I have a input:date and a select (for choose the operator).
FORM CODE:
<div id="info"></div>
<form>
<div id="input-form">
<input type="date" name="data" id="dataApp" onChange="checkDate()" required>
</div>
<div id="divSquadre">
<select name="squadra" onChange="orariApp()" id="squadra" required>
<option value="0">Operator 1</option>
<option value="1">Operator 2</option>
<option value="2">Operator 3</option>
</select>
</div>
</form>
The first function (checkDate) check the input date in DB and edit the select only with the "free-operator". The second function (orariApp), in this moment, show alert when it's called. i'm using this for "debug".
JS CODE:
function checkDate() {
var data=document.getElementById("dataApp").value;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("divSquadre").innerHTML = this.responseText;
}
};
xmlhttp.open("GET", "./ajax/checkSquadreInDataApp.php?data=" + data , true);
xmlhttp.send();
}
function orariApp() {
//if run function checkDate() this function doesn't work
alert("i'm working :)");
}
PHP checkSquadreInDataApp.php:
<?php
$data=$_REQUEST["data"];
$query = $mysqli->query('SELECT * FROM operators where data like "'.$data.'" and active is not null'); //example query
$squadra=$query->fetch_all(MYSQLI_BOTH);
echo '<select name="squadra" onChange="orariApp()" id="squadra" required>';
foreach($squadra as $el){
echo '<option value="'.$el['id'].'">'.$el['id'].'</option>';
}
echo '</select>';
Before i change date (start function checkDate) the function "orariApp" works. When function "checkDate" edit div "divSquadra", "orariApp" doesn't work anymore. Can someone help me?
Sorry for bad english :)