IE 9 jQuery not setting input value

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;
    }
});?

Answers:

Answer

From IE8 it is readonly try:

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

Picked from here : SO Anwser

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.