Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

184
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda