尝试使用JS附加到CSV文件



我是JavaScript和其他web技术的完全初学者,目前正在尝试将用户输入输入表单的数据附加到CSV文件。

这是我到目前为止所尝试的:

<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>

每当点击"提交"按钮,什么也没发生。任何帮助将非常感激!

这里有很多东西

& lt;形式id ="form"在

您正在发布犯罪数据,因此表单上应该有属性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 theaction '属性。

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>

需要更改经度和日期中的name属性。此外,当你在它,改变类型为number和设置最小和最大值的纬度和经度,日期应该是类型=date

至于你的submitCrime函数,你需要在最后调用return true,否则数据不会被提交。

<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>

相关内容

  • 没有找到相关文章

最新更新