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;
    }
});​
j08691
  • 204,283
  • 31
  • 260
  • 272
oSR
  • 127
  • 1
  • 2
  • 8

1 Answers1

2

From IE8 it is readonly try:

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

Picked from here : SO Anwser

Community
  • 1
  • 1
Suave Nti
  • 3,721
  • 11
  • 54
  • 78
  • [Try this](http://stackoverflow.com/questions/1043957/clearing-input-type-file-using-jquery). – The Alpha Jul 19 '12 at 19:07
  • 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. – oSR Jul 19 '12 at 20:08