Reputation: 2982
I'm currently working with form.attr
with jQuery and I have modified these to use the iframe
upload however now the upload has completed I need to revert these changes back. Is there an easy way to do this? For example form.revert()
or would I need to reset these using the form.attr()
function?
The code i was using is:
var form = $('.myform');
form.attr("action", "scripts/old.php");
form.attr("method", "post");
form.attr("enctype", "multipart/form-data");
form.attr("encoding", "multipart/form-data");
form.attr("target", "postiframe");
form.attr("file", $('#userfile').val());
but i now need to set it back to the original. I could use the above code again to reset but i would rather reset using a default method if possible
Upvotes: 1
Views: 61
Reputation: 66389
I assume you mean such code to make the form submit into an iframe?
var form = $("#form1");
form.attr("target", "MyFrame");
form.attr("action", "newpage.php");
form.submit();
In such case just store the original values as data values and revert right after submitting:
//get jQuery element:
var form = $("#form1");
//store original values:
form.data("original_target", form.attr("target"));
form.data("original_action", form.attr("action"));
//change values:
form.attr("target", "MyFrame");
form.attr("action", "newpage.php");
//submit:
form.submit();
//revert back to original:
form.attr("target", form.data("original_target"));
form.attr("action", form.data("original_action"));
And next submission will be in the main window, to original action page.
Upvotes: 1
Reputation: 411
Try it:
document.getElementById("formID").reset();
On the JSFIDDLE
Reference: w3schools
Upvotes: 2