Possible Duplicate:
IE 9 jQuery not setting input value
I would like to reset the input field if it matches some conditions using $(this).val("");
:
$(".checkimgextension").on("change", function () {
var file = $(this).val();
if (some conditions){
alert("wrong:...");
$(this).val("");
}
With Firefox the field is set to ""
, but with IE the field does not change as expected. Am using the right function .val("")
?
Refer to this: IE 9 jQuery not setting input value
$("input[type='file']").replaceWith($("input[type='file']").clone(true));
So in your case:
$(this).replaceWith($(this).clone(true));
instead of the $(this).val("");
line.
UPDATE:
In order to take advantage of browsers that allow you to modify the input:file
element, I would use something like this:
$(".checkimgextension").on("change", function () {
var $this = $(this);
if (some conditions) {
alert("wrong:...");
$this.val("");
var new_val = $this.val();
if (new_val !== "") {
$this.replaceWith($this.clone(true));
}
}
});
That way, it attempts to just set the value to empty at first, and if that doesn't succeed, use the replaceWith
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With