I have a jquery form that is submitted with FormData (and using iframe if formdata isn't available) however when the form is submitted another form is generated. as this form is going to use a jquery function to submit, the jquery function doesn't seem to be binded with the form so instead of using event.stopDefault(); it submits to its default i.e. test.php
Another words my question is: when a form is loaded by ajax is there a method/way to reload/bind the jquery function to the new form?
Example Code:
js code that i have tried:
$(document).on('#resize', submit, function(e) {
e.preventDefault();
e.stopPropagation();
if(window.FormData === undefined){
alert("Form Data not supported");
}
else{
var iframe = $('<iframe name="resizeiframe" id="resizeiframe" style="display: none" />');
$("body").append(iframe);
var form = $('#resize');
form.attr("action", "resizer.php");
form.attr("method", "post");
form.attr("enctype", "multipart/form-data");
form.attr("encoding", "multipart/form-data");
form.attr("target", "postiframe");
form.attr("file", $('#resizeimage').val());
form.submit();
$("#resizeiframe").load(function () {
iframeContents = $("#resizeiframe")[0].contentWindow.document.body.innerHTML;
$("#textarea").html(iframeContents);
$("#resizeiframe").remove();
$(document).find('#resizeiframe').remove();
});
}
});
form that is been submited after been generated by ajax but submitting regardless:
<form id="resize" action="resizer.php" method="post" onsubmit="return checkCoords();">
<input type="hidden" id="x" name="x" />
<input type="hidden" id="y" name="y" />
<input type="hidden" id="w" name="w" />
<input type="hidden" id="h" name="h" />
<input type="hidden" id="resizeimage" name="image" value="'.$new_name.'"/>
<input type="submit" value="Crop Image" class="btn btn-large btn-inverse" />
</form>
p.s i have tried removing the onsubmit but this doesn't make a difference.
$(document).on('submit','#resize',handler)