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

193
Vistas
Trying to append to CSV file using JS

I am a complete beginner to JavaScript and other web technologies and am currently trying to append the data the user enters into the input form to a CSV file.

This is what I have tried so far:

<form id="form">
            Type the latitude of the crime: <input type="text" name="latitude"><br>
            Type the longitude of the crime: <input type="text" name="latitude"><br>
            Enter the date in which the incident took place: <input type="text" name="latitude"><br>
            <input type="button" value="submit" id="submit-btn" onclick="submitCrime">
        </form>

        
        <script>
            //Clear form once submitted
            function clearForm(){
                document.getElementById("form").reset();
            }

            function submitCrime() {
            var formData = $("form").serializeArray();
            let csv = "data:/Users/duvalbalogun-palmer/Desktop/VGIS/php-shit/assault.csv;charset=utf-8,"; // accept data as CSV

            formData.forEach(function(item) {
            csv += item.value + ";"; // concat form value on csv var and add ; to create columns (you can change to , if want)
            });

            var encodedUri = encodeURI(csv);

            clearForm();
        </script>
    </body>
</head>

Whenever clicking on the "submit" button, nothing happens. Any help would greatly be appreciated!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You've got a number of things going on here

<form id="form">

You are posting crime data, so form should have the attribute method="form"' If what you posted isn't a part of a larger servlet / php / aspx file where you are handling the form submission, you should set the action` attribute on your form.

        Type the latitude of the crime: <input type="text" name="latitude"><br>
        Type the longitude of the crime: <input type="text" name="latitude"><br>
        Enter the date in which the incident took place: <input type="text" name="latitude"><br>
        <input type="button" value="submit" id="submit-btn" onclick="submitCrime">
    </form>

You need to change the name attribute in longitude and date. Also, while you are at it, change type to number and set min and max values for latitude and longitude, and date should be type=date

And as for your submitCrime function, you need to call return true at the end or the data won't get submitted.

<script>
    //Clear form once submitted
    function clearForm(){
        document.getElementById("form").reset();
    }

    function submitCrime() {
    var formData = $("form").serializeArray();
    let csv = "data:/Users/duvalbalogun-palmer/Desktop/VGIS/php-shit/assault.csv;charset=utf-8,"; // accept data as CSV

    formData.forEach(function(item) {
    csv += item.value + ";"; // concat form value on csv var and add ; to create columns (you can change to , if want)
    });

    var encodedUri = encodeURI(csv);

    clearForm();
</script>
about 4 years ago · Juan Pablo Isaza 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