Niklas Rosencrantz
Niklas Rosencrantz

Reputation: 26647

Are these clauses identical?

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();

?

Upvotes: 0

Views: 164

Answers (3)

Nigel B
Nigel B

Reputation: 3597

I don't think they are one condition is if status is true and it's not checked then asked for confirmation else do nothing. If status is not true or it is checked then do.

Upvotes: 1

Burhan Khalid
Burhan Khalid

Reputation: 174624

The first loop will only execute if the confirmation is positive; and if the checkbox is not checked and status is a true value.

Upvotes: 1

PeeHaa
PeeHaa

Reputation: 72662

No not the same. If both status and !checked evaluate to true, BUT the user doesn't confirm. nothing happens.

However note that it violates the DRY principle when doing it like that.

Upvotes: 5

Related Questions