0

I want to send more arguments through this onclick function, but I'm having trouble with the syntax. Any suggestions on how to do this?

 details_btn.onclick = new Function("moreInfo('"+user+"')");

I want to add three more arguments: phone and age

This just concatenates the strings:

 details_btn.onclick = new Function("moreInfo('"+user+phone+age"')"); 

I'd really appreciate the help. Thanks!

1 Answer 1

3

I want to send more arguments through this onclick function, but I'm having trouble with the syntax. Any suggestions on how to do this?

It should be like this instead:

details_btn.onclick = function(){
  moreInfo(user, phone, age); 
};
1
  • 1
    @Quentin the user, phone and age variables are defined outside the function and are carried in the scope chain of the anonymous function, I would argue that makes it a closure. Commented Feb 23, 2012 at 17:39

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.