Soy un completo principiante en JavaScript y otras tecnologías web y actualmente estoy tratando de agregar los datos que el usuario ingresa en el formulario de entrada a un archivo CSV.
Esto es lo que he probado hasta ahora:
<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>Siempre que haga clic en el botón "enviar", no sucede nada. ¡Cualquier ayuda sería muy apreciada!
Tienes varias cosas sucediendo aquí
<formulario id="formulario">
Está publicando datos sobre delitos, por lo que el formulario debe tener el atributo 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 acción` atributo en su formulario.
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>
Debe cambiar el atributo de name en longitud y fecha. Además, mientras lo hace, cambie el tipo a number y establezca los valores mínimo y máximo para la latitud y la longitud, y la fecha debe ser tipo = date
Y en cuanto a su función submitCrime, debe llamar a return true al final o los datos no se enviarán.
<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>