Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an "after submit" jQuery option?

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?

like image 816
polyhedron Avatar asked Mar 02 '11 15:03

polyhedron


People also ask

Is jQuery submit deprecated?

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 .

What does jQuery submit do?

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.

What happens on button submit?

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.

What does JavaScript submit () do?

submit() allows to initiate form sending from JavaScript. We can use it to dynamically create and send our own forms to server.


1 Answers

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 }); 
like image 51
lonesomeday Avatar answered Oct 04 '22 15:10

lonesomeday