Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
How do I pass a variable value which was collected from user input from one function to another

I am trying to create a page on htmlin HTML that automatically creates a pie chart with data provided from the user input form. I am trying to pass the values tax, mort, f, transport, and saving from collect() to drawChart() so that it could use those values to create the pie chart, but it doesn't seem to work. Does anyone know why?

function collect() {
  var tax = +document.getElementById("taxes").value;
  document.getElementById('tax').innerHTML = tax;

  var mort = +document.getElementById("mortage").value;
  document.getElementById('mort').innerHTML = mort;

  var f = +document.getElementById("food").value;
  document.getElementById('f').innerHTML = f;

  var transport = +document.getElementById("transportation").value;
  document.getElementById('transport').innerHTML = transport;

  var saving = +document.getElementById("savings").value;
  document.getElementById('saving').innerHTML = saving;

  drawChart(tax, mort, f, transport, saving);
}


function drawChart(val1, val2, val3, val4, val5) {

  var data = google.visualization.arrayToDataTable([
    ['Expense/Income', '$ per Month'],
    ['Taxes', val1],
    ['Mortage', val2],
    ['Food', val3],
    ['Transportation', val4],
    ['Savings', val5]
  ]);
  var options = {
    'title': 'Monthly Budget',
    'width': 550,
    'height': 400
  };

  // Display the chart inside the <div> element with id="piechart"
  var chart = new google.visualization.PieChart(document.getElementById('piechart'));
  chart.draw(data, options);
}
<div class="editTable">
  <div class="left">Taxes: </div>
  <div class="right"><input type="number" name="taxes" id="taxes"></div><br><br>
  <div class="left">Mortages: </div>
  <div class="right"><input type="number" name="mortage" id="mortage"></div><br><br>
  <div class="left">Food: </div>
  <div class="right"><input type="number" name="food" id="food"></div><br><br>
  <div class="left">Transportation: </div>
  <div class="right"><input type="number" name="transportation" id="transportation"></div><br><br>
  <button onclick="collect();" class="editRowBtn">Update</button><br><br>
</div>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!