2

If checked: #instructions-bar will activate. If not checked: #instructions-bar will not activate.

What's the best way to accomplish this within a case statement.. I know multiple if then statements wouldn't be the best way. Basically, I want to hide the #instructions-bar within each case. Not the whole switch.

<p><input type="checkbox" id="unique-checkbox-name" name="enable-checkbox"/>Checkbox</p>

 $("select[name=map-tool]").change(function (e) {
    var currVal = $(this).val();
    switch (currVal) {
        case "navigation":
            // instructions bar HIDE
            $('#instructions-bar').slideUp('slow');
            // more code
            break;
        case "distance":
            // instructions bar SHOW
            $('#instructions-bar').slideDown('slow');
           // more code
            break;
        case "area":
            // instructions bar HIDE
            $('#instructions-bar').slideUp('slow');
            // more code
            break;
    }
});

1 Answer 1

2
 $("select[name=map-tool]").change(function (e) {
    var currVal = $(this).val();
    var isChecked = $("#unique-checkbox-name").is(":checked");
    switch (currVal) {
        case "navigation":
            // instructions bar HIDE
            if (isChecked) $('#instructions-bar').slideUp('slow');
            // more code
            break;
        case "distance":
            // instructions bar SHOW
            if (isChecked) $('#instructions-bar').slideDown('slow');
           // more code
            break;
        case "area":
            // instructions bar HIDE
            if (isChecked) $('#instructions-bar').slideUp('slow');
            // more code
            break;
    }
});
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. Will this allow the case switch to run even if not checked? Confused. I only need the if statement on showing instructions-bar, not the rest.
Sorry, I didn't realize that is what you were asking for. I've updated my answer accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.