score:0

Accepted answer

add onclick event to the button and define a function plotchart():

<button id="submitter" onclick="plotchart()">submit</button>

now, to read the input value in the function:

var data = document.getelementbyid("userinput").value;

now, wrap all you chart plotting code inside plotchart() function.

score:0

you need to use the button event onclick, so every time you click it, you can then grab the input's value using a reference to the element. like the following snippet:

let someinput = document.getelementbyid('someinput')

function onbuttonclick() {
    let somevariable = parsefloat(someinput.value);
    console.info(somevariable);
}
<input id="someinput" type="number" />
<button onclick="onbuttonclick()">click me</button>

after this, you may use somevariable for anything you need.

notes:

  • use a type="number" input for better ux (so users can't input text or some other characters)
  • consider resetting the input value after clicking the button.

Related Query

More Query from same tag