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

334
Vistas
Trouble calling JavaScript function from html button

I am currently developing a website where users can enter their Australian postcodes and it will compare that to a .csv file I created that will return their local member of Parliament. I am using flask for the back end.

I am stuck at the moment, I have done some research and tinkered with some JS code that supposedly handles querying the .csv and returning the values I want which is here. My JavaScript file is in a "static" folder while I am keeping my html templates in a suitably named "templates" folder.

d3.csv("data/Members.csv").then(function (data)) {
  var members = data;
  var button = d3.select("#button");
  var form = d3.select("#form");
  button.on("click", runEnter);
  form.on("submit", runEnter);
}

function runEnter() {
  d3.select("tbody").html("");
  d3.event.preventDefault();
  var inputValue = d3.select("#user-input").property("value");
  var localMember = members.filter(members => members.Postcode.includes(inputValue));
  d3.select("tbody").insert("tr").html (
    "<td>" + (localMember["First Name" + "Surname"]) + "</a>" + "</td>" +
    "<td>" + (localMember["Electorate"]) + "</a>" + "</td>"
  );
  console.log(1 + 1);
  console.log(localMember["Electorate"]);
}

I believe it is being found by my .html file because I'm not getting any 404 errors, however the button does not return any console logs or execute the function. Here is the relevant code from my html file.

<head>
<script src="https://d3js.org/d3.v5.min.js"></script>
</head>

-----------------------------------------------------------------------------

<div class="item5">
    <p class="pform">Postcode</p>
    <form id="form">
      <input type="text" id="user-input">
      <input type="button" id="button" value="click here">
    </form>
  </div>

  <div class="item6">
    <thead>
      <tr>
        <th scope="col">Name</th>
        <th scope="col">Electorate</th>
      </tr>
    </thead>
    <tbody>
  </div>

</div>

  </body>

  <script {{url_for('static', filename='app.js')}}></script>

</html>
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Put code:

  var button = d3.select("#button");
  var form = d3.select("#form");
  button.on("click", runEnter);
  form.on("submit", runEnter);

out from d3.csv("data/Members.csv").then(function (data)) {...}

https://jsfiddle.net/artee2025/auw6zrdp/2/

over 4 years ago · Santiago Trujillo Denunciar
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