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.
Source: stackoverflow.com
Related Query
- HTML Input Form to a Javascript Variable
- Javascript and Chart.js not taking user input assuming it is a variable scope issue
- How pass a variable from code behind to javascript
- Parse HTML input value to php over javascript file
- Passing data to highcharts from javascript array or variable
- Calling external Chartjs chart from a javascript file into HTML in Flask
- Passing an Array from a Flask view to the javascript code of another view
- JavaScript & HTML - reusing data from fetch()
- Displaying data from simple html form to display in chartjs
- How to loop inside javascript using php variable
- How to sum the array value in javascript like chartjs data array and input value sum
- Creating and Updating Graph in HTML and Javascript
- How can have variable data be from a url in javascript
- How to pass variable (list) to JavaScript in Django?
- How to use output of JSON.parse() as a input of HTML charts' data field?
- JavaScript variable in an object
- Php/ajax return JSON in same form as javascript array
- Variable in JavaScript with firebase
- Reference Javascript variable in JSON
- Using data saved as a variable in HTML from Python
- 'require is not defined' error when attempting to use chartjs in javascript code
- increasing php variable in javascript loop
- Getting the HTML code of a chart created by chart.js
- How to run Chart.js samples using source code
- Adapting a JavaScript code to be dynamic
- Does iFrame have any events suitable for when a JavaScript & HTML page are embedded in modal(Bootstrap)
- how do i use the numbers i key in from a form as the input data for chartjs
- Javascript highcharts code similar to image
- JavaScript Chart.js - Custom data formatting to display on tooltip
- Dynamically update the options of a chart in chartjs using Javascript
More Query from same tag
- Chart.js version 2.5 tooltip align items horizontally
- ChartJS doughnut chart not displaying colours
- Changing the label of chart
- Chartjs - Insert additional data into chart tooltip
- Chart is disappearing during # link
- how to resize specific gridline(s) in chart.js
- Dynamically create dataset objects for multi-line graphing, using pre-defined dataset object arrays (JavaScript / Chart.js)
- Collect json disordered, order it and show it in chart.js
- How to filter chart.js with datepicker?
- 【React chart.js】How to add multiple data to Radar chart using map function
- chart.js hide x/y axis, customize
- Data Labels on top of points in line charts
- ChartJs - Adding padding after Y- Axis
- Adding X axis title causes Uncaught RangeError: minimumFractionDigits value is out of range in Chart.js
- Chartjs - tooltip - different corner radius
- How can i implement RTL for Yaxis in Chartjs
- Loading json file to chartjs
- Chartjs numbers on bar chart flash on hover
- Set backgroundColor of bar-char (chart.js)
- Pie chart using chart.js and asp.net web Service (asmx)
- Adding a label to a doughnut chart in Chart.js shows all values in each chart
- Chart JS: Donut/Doughnut Chart: Tooltip to be shown always for all the data. All tooltip is not shown when multiple data are with 0 data
- I would like to rotate yAxes scaleLabel in Angular Chart.js
- Avoiding Empty Curly Braces in MongoDB Aggregation
- How do we can use chart.js in angular JS?
- ng-repeat in ChartJS AngularJS
- How to disable canvas elements from hijacking mouse wheel when scrolling through a page?
- ChartJS Horizontal Bar is displaying backwards
- ChartJS canvas not displaying rgba colors in IE, Safari and Firefox
- Chart.js how to get Combined Bar and line charts?