user3401408
user3401408

Reputation:

What's the error in my javascript code?

Here is my javascript code, I'm getting error Uncaught SyntaxError: Unexpected token ILLEGAL at Line no 37

I was trying to append the options to "select" list from a json, my code seems to be have no syntax error. but chrome is throwing one.

31 set_options_list = function(selctelm, json){
32  $(selctelm).empty();
33  $.each(json, function(k, val) {
34     $(selctelm).append(
35              $("<option></option>").text(val).val(val)
36     )
37  });​
38 }

Upvotes: 5

Views: 114

Answers (3)

Nurdin
Nurdin

Reputation: 23911

I found out your code missing some tag.

set_options_list = function(selctelm, json) {
    $(selctelm).empty();
    $.each(json, function(k, val) {
        $(selctelm).append(
        $("<option></option>").text(val).val(val));
    });
};

Upvotes: -1

xdazz
xdazz

Reputation: 160963

There is an invisible char (zero-width space U+200B) after }); in line 37.

I copied your code to my editor

Upvotes: 11

Sridhar R
Sridhar R

Reputation: 20428

Remove illigeal character

Try this Jquery;

set_options_list = function(selctelm, json){
$(selctelm).empty();
$.each(json, function(k, val) {
$(selctelm).append($("<option></option>").text(val).val(val)); // Here semicolon
 });​//Here there is illegal character
}

Upvotes: 1

Related Questions