I have a form
<form name="thumbnail" action="<?php echo $_SERVER["PHP_SELF"];?>" method="post">
<input type="hidden" name="x1" value="" id="x1" />
<input type="hidden" name="y1" value="" id="y1" />
<input type="hidden" name="x2" value="" id="x2" />
<input type="hidden" name="y2" value="" id="y2" />
<input type="hidden" name="w" value="" id="w" />
<input type="hidden" name="h" value="" id="h" />
<input type="submit" name="upload_thumbnail" value="Save Image" id="save_thumb"/>
<?php $_SESSION['image1'] = $thumb_image_name.$_SESSION['user_file_ext'];?>
</form>
I want to close this form after completing this function
$(document).ready(function () {
$('#save_thumb').click(function() {
var x1 = $('#x1').val();
var y1 = $('#y1').val();
var x2 = $('#x2').val();
var y2 = $('#y2').val();
var w = $('#w').val();
var h = $('#h').val();
if(x1=="" || y1=="" || x2=="" || y2=="" || w=="" || h==""){
alert("Please Select Area to Crop");
}else{
return true;
}
});
});
Problem is that if I put window.close(); before return true; window closes but form does not submit, and if I put it after return true; then the window will not close.
This is not working
$("thumbnail").submit(function() {
$.post($(this).attr('action'), $(this).serializeArray());
window.close();
});
This is also not working:
function closeSelf(){
document.forms['thumbnail'].submit();
window.close();
}
<input type="submit" name="upload_thumbnail" value="Save Image" id="save_thumb" onclick="closeSelf();"/>
An ajax form submission might help you out. On click you submit the form and the on completion of ajax request you can close the window. Something like this
$(document).ready(function () {
$('[name="thumbnail"]').submit(function() {
<Perform your validation here>
$.ajax({
url: $('[name="thumbnail"]').attr('action'),
method: 'post',
data: $('[name="thumbnail"]').serialize(),
success: function (data, status) {
window.close();
}
}
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments