-2

I wrote this script but it think something is wrong with the syntax since it wont execute could you please tell me whats wrong?

<script type="text/jscript">
    var subcategoriesUrl = '@Url.Action("GetSubCategories")';
    var subcategories = $('#SelectedSubCategory');
    $(document).ready(function () {
        $('#SelectedCategory').change(function () {
            subcategories.empty();
            $.getJSON(subcategoriesUrl, { idSubCategory: $(this).val() },function(data) {
                if (!data) {
                    return;
                }
                subcategories.append($('<option></option>').val('').text('Hello'));
                $.each(data, function(index, item) {
                    subcategories.append($('<option></option>').val(item.Value).text(item.Text));
                });
            });
        });
    });
    });
</script>
mdiaz
  • 27
  • 1
  • 10
  • 2
    Look at the Console in your developer tools or http://jshint.com/ to see what is wrong with the syntax. Use – Quentin Mar 15 '16 at 23:12
  • 2
    That indentation is terrible. Five `});` tacked on at the end? No wonder you can't find the problem. I threw it in jsfiddle and had it format the code. Looks like you might have one too many `});` at the end: https://jsfiddle.net/Ljjx7h5p/, but I can't tell for certain if that is really why it's not working. – Joseph Marikle Mar 15 '16 at 23:14

2 Answers2

1

type="text/jscript" should be type="text/javascript" and there is an extra }); at the end

Rafael Grillo
  • 232
  • 2
  • 8
1

you seem to have added one }); too much.

Holly
  • 43
  • 4