user160820
user160820

Reputation: 15230

Javascript Syntax Error

hiere is my code, within a loop. I want to solve my closure problem. But on click I receive an error message "Syntac Error". Any help. Thanks in advance.

var html  = '<div style="margin-top:10px">';
    html += '<div class="weiter">  Kartenauswahl in die Recherche &uuml;bernehmen </div>';
    html += '<div class="weiter" style="display:block;clear:left;margin-top:7px" 
              onclick="function(obj) { return getChildObject(obj)}(obj)">Weiter</div>';
    html += '</div>';

Upvotes: -1

Views: 117

Answers (5)

aquasmit
aquasmit

Reputation: 411

function(obj) { return getChildObject(obj)}(obj)

Above does not seems to be correct

Upvotes: 0

Tim Down
Tim Down

Reputation: 324727

If that's your actual code, the immediate problem is that there's a line break in your string literal, between the third and fourth lines. Delete that line break. There are problems in the HTML too, as mentioned in other answers.

Upvotes: 1

Oded
Oded

Reputation: 499382

This certainly does not look right:

function(obj) { return getChildObject(obj)}(obj)

I would simply write this:

return getChildObject(obj);

Upvotes: 3

Sarfraz
Sarfraz

Reputation: 382909

The problem seems to be at:

onclick="function(obj) { return getChildObject(obj)}(obj)
                                                      ^

Try removing (obj).

Also you should post the code for getChildObject function.

Upvotes: 0

Gumbo
Gumbo

Reputation: 655815

This code in your onclick attribute is not valid:

function(obj) { return getChildObject(obj)}(obj)

Put the function expression in parentheses and try this instead:

(function(obj) { return getChildObject(obj); })(obj)

Upvotes: 2

Related Questions