-2

My ajax code below will stop the form pprocess if an input value is empty, then showing an popup alert. The problem is, the process will continue after the alert popup closed. How can i stop the process until the input value is not empty?

$("#spdf-form").on('submit', function () {

var title = $('#spdf-form input[name="title"]').val();
var url = $('#spdf-form input[name="pdf"]').val();

if (title == "" || url == "") {
        alert('Error; title or url is missing.');
    return false;
}

});
4

1 回答 1

1
$("#spdf-form").on('submit', function (e) {

    var title = $('#spdf-form input[name="title"]').val();
    var url = $('#spdf-form input[name="pdf"]').val();

    if (title == "" || url == "") {
        alert('Error; title or url is missing.');
        e.preventDefault();
        return false;
    }

});
于 2013-05-20T23:28:52.627 回答