logo

New Response

« Return to the main article

You are replying to:

    • avatar
    • Matt
    • Posted on Wed 23 Jun 2010

    Hello everyone... I did a few modifications for our site and thought I'd share it with you all. The only thing I just found out is IE doesn't fire off the check so I'm looking into that. If anybody knows why feel free to reply. :)

    function TestFileType(fileName, fileTypes) {

    var myReturn = false;

    if (!fileName) return;

    dots = fileName.split(".");

    //get the part AFTER the LAST period.

    fileType = dots[dots.length-1];

    if (fileTypes.indexOf(fileType) != -1)

    myReturn = true;

    else{

    alert("Please only upload files that end in types: \n\n" + (fileTypes.join(" .")) + "\n\nPlease select a new file and try again.");

    document.getElementById('cf_file').value = '';

    }

    return myReturn;

    }

    cfinput/input attribute call: onChange="TestFileType(this.form.cv_file.value, ['doc', 'docx', 'pdf']);"

    I chose to use onChange instead of onClick or onBlur. onChange checks it after making the selection. onClick wouldn't work in FF or IE and onBlur only worked after you left the field in FF (didn't work at all in IE)

    I also chose to do the if else instead of the ? : simply because I couldn't get it to do what I wanted it to do (clearing the field after sending the alert) and as far as the message being okay I didn't need to send a file is ok alert. Nevertheless this has helped greatly, thank you everyone for your input and for the original code! We'll be using this more I'm sure. :) That way we can try and prevent everything having to be checked on the server side.

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment: