1

my question is simple:

I have an input file field, and i want to limit it to only accept .GIFs via Jquery , and if the format is wrong, set the input value blank.

The problem is that on IE9, the .val('') does not work. Any ideas?

My jQuery:

$('input[type=file]').change(function() {
    var val = $(this).val();
    switch (val.substring(val.lastIndexOf('.') + 1).toLowerCase()) {
    case 'gif':
        break;
    default:
        // error message here
        alert("Wrong Format");
        $(this).val('');
        break;
    }
});​
3
  • 1
    I think from IE8 File Upload field is read-only... Commented Jul 19, 2012 at 19:01
  • 1
    AFAIK the file input is readonly you can't change it's value programmatically. Commented Jul 19, 2012 at 19:01
  • Thanks for the help guys, i did not know it was a readonly field on IE8/9 Commented Jul 19, 2012 at 20:09

1 Answer 1

2

From IE8 it is readonly try:

$("input[type='file']").replaceWith($("input[type='file']").clone(true));

Picked from here : SO Anwser

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the help, it really helped me. Although the name of the file remains in the input field, in the 'logic' part the input is empty.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.