0

I have a dynamic select change option used jquery append the option. I need to add many option list. However I get error when I put line break between.

$("#country").change(function(){
    switch($("#country").val()){
        case "usa":$("#state").append("<option value='AL'>Alabama</option><option value='CA'>California</option>...");break         
        case "aus":$("#state").append("..");break...    
    }
});

I got error when I put line break between,is any way to solve this problem, because I need to add many option list. it's very hard to edit without the line break.

case "usa":$("#state").append("
    <option value='AL'>Alabama</option>
    <option value='CA'>California</option>...
");break
user2178521
  • 833
  • 1
  • 14
  • 26

1 Answers1

5

You need to escape the line break in the string, see: Creating multiline strings in JavaScript

case "usa":$("#state").append(" \
    <option value='AL'>Alabama</option> \
    <option value='CA'>California</option>... \
");break
Community
  • 1
  • 1
CodingIntrigue
  • 75,930
  • 30
  • 170
  • 176