The following is what I'd like to do in my JQuery script. In the submit function (4th) below, I want to decide if the form has file input and submit with either ajax or just a regular form submit without ajax. In other words, if the form has upload, do a regular submit.
I wrote the question in the submit function below. That is the only thing I need to make it work.
Thank you!
function FindFileInput(){
// check for file input
var FileInput = $('input:file');
if(FileInput.length > 0){
return true;
}else{
return false;
}
}
function validation(){
// code to validate form
...
}
function ajaxSubmit(formData){
$.ajax({
// ajax submit code
});
}
$(myForm).submit(function(e){
e.preventDefault();
// 1. if NO file input present
if(FindFileInput() === false){
if(validation() === true){
// serialize and call ajaxSubmit function
}
}
// 2. if file input IS present
if(FindFileInput() === true){
if(validation() === true){
// QUESTION: How do I submit the form here???
}
}
});