0

I am trying to call javascript function on "OnClick" event of a link as

var xx = 'test str';

breadcrumbStr = onClick="CategoryMaster.expandNode(xx)">'+xx

It works only when I call the function without parameter. I want to execute this function with parameter.

Please help me.Thanks

4
  • I'm terribly confused by that code. Why don't you set onClick to be "CategoryMaster.expandNode(this)" or something like that? Commented Jan 28, 2011 at 14:46
  • 2
    What is breadcrumbStr ? What is onClick here? There are syntax errors in your code. It is not all clear what you want to do... Commented Jan 28, 2011 at 14:47
  • ?? huh ? the code you posted is obviously not copy/pasted correctly. Please add a real example.. Commented Jan 28, 2011 at 14:49
  • use jsfiddle.net to give a broad picture as to what your requirement is. Commented Jan 28, 2011 at 15:10

3 Answers 3

1

Assuming breadcrumbStr is the link you want to attach the event handler to, this is the closest what I can come up with given your code:

breadcrumbStr.onclick = function() {
    CategoryMaster.expandNode(xx);
}

Not sure what the string concatenation is about.

Sign up to request clarification or add additional context in comments.

Comments

0

Apart from the senseless code...
You can use window.xx in that case. Variables are normally declared in the global scope which is window. You can access every global variable through that, which is window.xx here.

Comments

0

onClick in html expects an actual function 'object'. what you have is a funciton call. try

onClick="function(){ CategoryMaster.expandNode(xx); }"

1 Comment

You are still assigning a string.

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.