I’m looking at a javascript that my colleague wrote and I think that it looks like it does the same in both clauses:
function doSubmitOversikt(action, command, status) {
var checked = document.getElementById("klarbox").checked;
if(status && !checked) {
if (confirm("Ärendet är satt som Klar (formell handläggning första delen klar). Vill du verkligen ångra detta? Att ångra kan innebära att ärendet behöver arras om i CICS.")) {
document.actionForm.action.value = action;
document.actionForm.actionCommand.value = command;
document.actionForm.submit();
disableAll();
}
} else {
document.actionForm.action.value = action;
document.actionForm.actionCommand.value = command;
document.actionForm.submit();
disableAll();
}
}
What will be the difference between the above code and to unconditionally do
document.actionForm.action.value = action;
document.actionForm.actionCommand.value = command;
document.actionForm.submit();
disableAll();
?
No not the same. If both
statusand!checkedevaluate to true, BUT the user doesn’t confirm. nothing happens.However note that it violates the DRY principle when doing it like that.