Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda