This Run like it is perfectly fine.
// Save, set state to finalized and Print
$('#btnDialogPrint').click(function () {
if ($('#chkFinal').is(':checked')) {
$(function () {
$("#PrintDialog").dialog('close');
});
}
else {
$('#chkFinal').attr('checked', true); // Set finalized. This checkbox is not visible its like a hidden field
$('#btnSubmit').click(); // Save
}
});
And this also runs fine:
window.location = '../Print/' + $('#SalesContractId').val();
But when i put them together it only run’s the
window.location = ‘../Print/’ + $(‘#SalesContractId’).val();
Complete Code:
// Save, set state to finalized and Print
$('#btnDialogPrint').click(function () {
if ($('#chkFinal').is(':checked')) {
$(function () {
$("#PrintDialog").dialog('close');
window.location = '../Print/' + $('#SalesContractId').val(); // Moves to ContractController Print
});
}
else {
$('#chkFinal').attr('checked', true); // Set finalized. This checkbox is not visible its like a hidden field
$('#btnSubmit').click(); // Save
window.location = '../Print/' + $('#SalesContractId').val(); // does not alow above code to execute
}
});
Remove the
$(function() { ... });inside the click handler and put it ouside:The
$(function() { ... });means document.ready.This being said you seem to be calling some
$('#btnSubmit').click();. Note that if this#btnSubmitis actually the submit button of some form (as its id suggests) then when the form is submitted it will automatically redirect the browser to theactionattribute of the form. So it is completely meaningless to callwindow.location.hrefto redirect in this case. I guess you will have to rethink whatever you are trying to achieve.