如何避免表单中的文本字段清除onClick?

时间:2016-05-31 21:23:11

标签: javascript jquery html

我有一个包含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);
}

0 个答案:

没有答案