我有一个包含4个文本字段的简单表单。当用户单击保存按钮以保存这些字段的内容时,文本字段将自动清除。我该如何避免?
这是我运行onclick
的函数:
function saveProblem() {
var location = document.getElementById("txtinput_location").value;
var description = document.getElementById("description").value;
var importance = document.getElementById("importance").value;
var type = document.getElementById("problemtype").value;
var datetime = new Date();
var date = "Dato: " + datetime.toLocaleDateString() + " KL: " + datetime.getHours() + ":" + datetime.getMinutes();
if (location === "" || description === "" || description === "" || importance === "") {
alert("\nALLE FELTER SKAL UDFYLDES!");
} else {
problem_array.push(new Problem(location, description, importance, type, date));
}
console.log("OBJECT: " + location + " " + importance + " " + type + " " + description + " " + date);
console.log("Array lenght: " + problem_array.length);
}