I have separated my form in different functions and although each one works, I can't find a way to use the value returned in the total function.
function adult() {
let a = document.getElementById("adulte").value;
let t = a * 100
document.getElementById("asub").innerHTML = t
//document.getElementById("sub-a").value = t;
console.log(t);
document.getElementById("tprice").innerHTML = a;
return t;
}
function total() {
let a = adult();
document.getElementById("tprice").innerHTML = a;
console.log(a);
}
<input id="adulte" name="adulte" style="width: 40px" onchange="adult();" />
<span id="aprice"> 100</span>$/nuit
<p> Hébergements pour les adultes = <span id="asub">100</span>$</p>
<button id="total" name="total" onclick="total();">calculate</button>
<span id="tprice"> 50</span>$