javascript - send on post only files that are not empty -


i have 3 input file on form:

<td><input type="file" name="image_url1"/></td> <td><input type="file" name="image_url2"/></td> <td><input type="file" name="image_url3"/></td> 

i want send (on post) files selected (input files stay empty => don't send them).

how can that?

you can use .length check file length, , disable empty controls. way not posted.

 $('input[type=file]').each(function () {         if (this.value == "" || this.files.length == 0) {             this.prop('disabled', true)         }      }); 

update: if not using jquery, can simple javascript as:

var myfiles = document.queryselectorall("input[type=file]"); for(var = 0; i<myfiles.length; i++) {    if(myfiles[i].value == "" || myfiles[i].files.length == 0)    {       myfiles[i].disabled = true;    }   } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -