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?
No, it's not deprecated! Deprecated = Not current. Obsolete = no longer available. IMHO the reason is because as browsers/html standards add more events, the team doesn't want to keep adding aliases when .
jQuery submit() Method The submit event occurs when a form is submitted. This event can only be used on <form> elements. The submit() method triggers the submit event, or attaches a function to run when a submit event occurs.
Most HTML forms have a submit button at the bottom of the form. Once all of the fields in the form have been filled in, the user clicks on the submit button to record the form data. The standard behaviour is to gather all of the data that were entered into the form and send it to another program to be processed.
submit() allows to initiate form sending from JavaScript. We can use it to dynamically create and send our own forms to server.
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 });
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