I'm still relatively new to HTML and Javascript code so this could just be a minor stupid error.
Basically I'm trying to use chartjs to create a line chart and for one of those lines I want the user to be able to enter their own data, so I've been testing out a few methods but can't figure out why they won't work.
I was hoping to use document.getElementById to take the value of the first number input and then use it as a data value for the line chart, for example:
data: [addData(), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
This is how the function to add the input value as data is called, then the function itself is:
function addData() {
var input = document.getElementById("testId").value;
}
I've also tried to use return input; but the whole chart just disappears when I use either of those, however if I use the function below for addData() the chart still works fine and accepts 2 as the first data value:
function addData() {
var input = 2;
return input;
}
Here is the number input code:
Birth: <input type="number" maxlength="4" id="testId" value="2"><br>
Any ideas why the entire chart disappears when I attempt to use a number input field for the data value?
EDIT: I've just solved this now thanks to Shai Aharoni for pointing out any possible errors, I just needed to rearrange the order of the input field to be before the script, just a silly error.