G
G
Ghost26922018-02-05 18:42:44
JavaScript
Ghost2692, 2018-02-05 18:42:44

How to properly validate a file with jquery?

I have bad code for sending.
When you select a file, it checks for the appropriate file type, if the type is suitable, you can send it, if not, it shows an error message and you cannot send the file.
If the correct file is selected, it is still impossible to send the file, how to solve this problem?

var filesExt = ['csv'];
    $('#addcontactsfile-contact_file').change(function () {
        var parts = $(this).val().split('.');
        if (filesExt.join().search(parts[parts.length - 1]) != -1) {
            $("#file-help").css('display', 'none');
            $("#file-submit").click(function () {
                $('#add-contacts-file').submit(true);
            });
        } else {
            $("#file-help").css('display', 'inline-block');
            $("#file-submit").click(function () {
                $('#add-contacts-file').submit(false);
            });
        }
    });

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question