I have the following form
<form name="myForm" id="myForm" method="post" enctype="multipart/form-data" action="script.php">
and this jQuery
$(document).ready(function() {
$('#previewButton').click(function() {
// Change form's target to be in a new window.
$('#myForm').attr('target', '_blank');
/*
* Create a hidden input field and add it to the form to designate that the
* action the form is performing is a preview action.
*/
$('#myForm').append($('<input id=\"previewAction\" name="previewAction" type=\"hidden\" />'));
// Submit the form.
$('#myForm').submit();
// Change the form's target to be the current page again.
$('#myForm').attr('target', '');
/*
* Remove the hidden input field we just added so that the form can submit
* normally.
*/
$('#previewAction').remove();
return false;
});
});
I have this exact same two code on two different pages. On one, when I click my Preview link, the form submits to a new, blank window. On the other page, the form does not submit, and no window opens when I click Preview.
.click() IS running, and I know this because I put a call to alert() in .click() and was presented with an alert box.
From running the following, I can see that .submit() for my form is NOT overridden anywhere else:
var submitEvents = $('#myForm').data("events").submit;
jQuery.each(submitEvents, function(key, value) {
alert(value);
});
Also, I get no Javascript errors.
And ideas why clicking Preview (apparently) does nothing?