samedi 1 août 2015

Stop form submission if textfield is empty

Trying to stop a form submission when textfield is empty. But with my current script even when the textfield is empty and you should and check the database you can see a newly inserted empty records

$(document).ready(function(){

    $("#form1").on('submit',function(event){
        event.preventDefault();

if ($("#username").val() != '') {
    }
        data = $(this).serialize();
        $.ajax({
        type: "POST",
         url: "username.php",
        data: data
        }).success(function() {
        $("input[type=text]").val("");


        });
    });
});

Aucun commentaire:

Enregistrer un commentaire