Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
145
rated 0 times [  146] [ 1]  / answers: 1 / hits: 90728  / 14 Years ago, wed, march 2, 2011, 12:00:00

I have a form that uploads a file and targets an iframe on the page. When the user clicks submit, I want the file contents to clear out.



I tried this



$('#imageaddform').submit(function(){
$('#imagefile').val('');
});


But it clears the form before the submit, so nothing is ever uploaded.



Is how do I clear after submit?


More From » jquery

 Answers
7

If you have no other handlers bound, you could do something like this:



$('#imageaddform').submit(function(e) {
e.preventDefault(); // don't submit multiple times
this.submit(); // use the native submit method of the form element
$('#imagefile').val(''); // blank the input
});

[#93497] Tuesday, March 1, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
efren

Total Points: 186
Total Questions: 85
Total Answers: 112

Location: Turkmenistan
Member since Sat, Apr 16, 2022
2 Years ago
;