tags:

views:

57

answers:

5

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>';
+2  A: 

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)
Gumbo
+1 Although in this case OP could simply use `return getChildObject(obj);`.
Groo
A: 

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.

Sarfraz
+3  A: 

This certainly does not look right:

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

I would simply write this:

return getChildObject(obj);
Oded
+1  A: 

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.

Tim Down
A: 

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

Above does not seems to be correct