So a little hard to explain in the title. Technically the script is being executed in order but does not wait for the next function to be done before executing the next. Is there any way to do this?
<form action="" method="POST">
<input type="submit" style="background:transparent;border:0;color:#ffffff;" name="approve" id="approve" value="approve shipment" />
<input type="hidden" name="ShipmentDigest" value="<?php echo $responseArray['ShipmentConfirmResponse']['ShipmentDigest']['VALUE']; ?>" />
</form>
Javascript:
<script>
document.getElementById('approve').click();
setTimeout(function(){
window.print();
},2000);
close();
</script>
So basically I am generating an UPS label and upon if ($approve == 'approve shipment')
then it will generate the label and download to server as well as I want it to pop up for the user to print and then regardless of selection of "Print" or "Cancel" close out that pop up window.
The issue is that the button is a form submit which then reloads the page and script just keeps executing if I remove the close();
Right now, the script will click on the approve
button and then starts the timer and then closes before the time has completed. If I change the code to having close();
within the wait, it just keeps clicking on approve
and never lets the timer run:
<script>
document.getElementById('approve').click();
setTimeout(function(){
window.print();
close();
},2000);
</script>