Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

JQuery on change hitting default

I am trying to dynamically load content with select.

$(document).ready(function () {
    $("#lang").on("change", function () {
        switch(this.value) {
            case "pl":
                $("#content").load("pl.html");
            case "en":
                $("#content").load("en.html");
            default:
                alert("default")
        }
    });
});
<select name="lang" id="lang">
    <option value="en">en</option>
    <option value="pl">pl</option>
</select>
<div id="content"></div>

Whenever I am changing value the default alert is occurring and the content is not always updated properly.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If break is omitted, execution will proceed to the next case clause, even to the default clause, regardless of whether the value of that clause matches.

enter link description here

$(document).ready(function() {
  $("#lang").on("change", function() {
    switch (this.value) {
      case "pl":
        $("#content").load("pl.html");
        break;
      case "en":
        $("#content").load("en.html");
        break;
      default:
        alert("default")
        break;
    }
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="lang" id="lang">
  <option value="en">en</option>
  <option value="pl">pl</option>
</select>
<div id="content"></div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading