Answer the question
In order to leave comments, you need to log in
Why doesn't the form submit on the change event?
$("input[type=file]").on('change', function (e) {
$($(this).siblings('input[type=submit]')).click( function( e ) {
console.log(this);
e.preventDefault();
} );
});
Answer the question
In order to leave comments, you need to log in
The form can also work by pressing Enter , for example. So, it's not right to catch a click on a submit.
You can do it like this:
$("form").on("submit", function(e){
$("input[type=file]").val()||e.preventDefault();
});
var acess = false;
$("input[type=file]").one("change", function(){
acess = true;
});
$("form").on("submit", function(e){
acess||e.preventDefault();
});
var form = $("form");
form.on("submit", function(){
e.preventDefault();
}).siblings("input[type=file]")
.one("change", function(){
form.off("submit");
});
//При выборе файла
$("input[type=file]").on('change', function (e) {
//Ставим обработчик
$($(this).siblings('input[type=submit]')).click( function( e ) {
//Который запрещает отправку формы по нажатию на кнопку
e.preventDefault();
});
});
So you have e.preventDefault(); which just cancels the form submission.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question