I cant seem to work out why parseInt() is not working properly in my code when I try to pass numbers through to my function parameters. It seems to keep coming up with NaN both in my array and the function return value.
What I am trying to do is when values are keyed into the input fields the index percentage of these two values appears in the HTML and stores the value in an array. I am using a function for this because I want to have over twenty outlet calculations. I am also struggling with refactoring this code as I don't have a lot of experience with JS. Any help would be really appreciated.
Here is my HTML.
function outletIndex(actual, design) {
let result1 = actual / design * 100;
var indexArray = [];
indexArray.push(result1);
console.log(indexArray, result1);
if (!isNaN(result1)) {
document.getElementById("percentage").textContent = `${result1.toFixed(1)}%`;
}
}
const x = parseInt(document.getElementById("outlet_actual_1" ).valueAsNumber);
const y = parseInt(document.getElementById("outlet_design_1").valueAsNumber);
const outlet1Index = outletIndex(x, y);
<table>
<tr>
<div class="form-group row 1" id="outlets1">
<td><label
>Outlet Design</label>
<input
name = "outlet 1 design"
class="form-control design_1"
id="outlet_design_1"
type="number"
placeholder="Outlet 1 Design"
/>
</td>
<td><label
>Outlet Actual</label>
<input
name="outlet 1 actual"
class="form-control actual_1"
id="outlet_actual_1"
type="number"
placeholder="Outlet 1 Actual"
onblur="outletIndex();"
/>
</td>
<td><label
>Outlet Balance</label>
<input
name="outlet_balance"
class="form-control"
input value=""
id="outlet_balance_1"
type="text"
placeholder="Outlet 1 Balance"
/>
</td><td>
<div class="proportion" id="percentage">
</div>
</td>
</div>
</tr>