-1

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>';
1
  • Instead of using string to create your dom, you could create DOM objects. Commented Jul 20, 2010 at 10:20

5 Answers 5

3

This certainly does not look right:

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

I would simply write this:

return getChildObject(obj);
Sign up to request clarification or add additional context in comments.

Comments

2

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)

1 Comment

+1 Although in this case OP could simply use return getChildObject(obj);.
1

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.

Comments

0

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.

Comments

0

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

Above does not seems to be correct

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.