1

I want to pass Object in function. Here is my code

var hyperLinkObj = new Object();
hyperLinkObj.path="abc";
hyperLinkObj.text="abctext";

'<li><a href="#" onclick="onItemClick(hyperLinkObj)">'+description+'</a></li>'

Here I am creating Object called as "hyperLinkObj" Now I am creating "li" tag and putting hyperlink in li Now When I inspect the I am getting something like

'<li><a href="#" onclick="onItemClick([object Object])">'+description+'</a></li>'

So How can I pass the hyperLinkObject , as in the onItemClick I have do many thing on this Object.

See Actually I wanted to do something like this.

1] There is an Object which has many Category So wanted to loop through it. 2] then on Each category item click wanted to call OnItemClcik with hyperLinkObj 3] Then on click of on Hyperlink , wanted to do operation like fetching Hyperlink.path and show the Breadcrumb. 4] and finally I am using Extjs So Ext.Panel.update("Li text");

May be I didnt mentioned that ExtJs.update.. it is not working as per your suggestion..

Can you explain How can I achive this ?

3
  • What is the object supposed to reference in relationship to the clicked list item? Commented Apr 9, 2013 at 13:54
  • 1
    var hyperLinkObj = { path: "abc", text: "abctext" }; Preferred syntax for objects. Commented Apr 9, 2013 at 13:55
  • Where is hyperLinkObj created? Global scope? Can you show how you intend to use it in the onItemClick function? Commented Apr 9, 2013 at 13:59

2 Answers 2

2

Put hyperLinkObj in global scope, and refer to it in the onclick.

hyperLinkObj = new Object();
hyperLinkObj.path="abc";
hyperLinkObj.text="abctext";
Ext.Panel.update('<li><a href="#" onclick=\'onItemClick({path:"'+hyperLinkObj.path+'",text:"'+hyperLinkObj.text+'"})\'>'+description+'</a></li>')

[object Object] is the toString() of an Object(), and contains no details.

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

1 Comment

I cant use the Global object as It will be in loop., I have explain the senario above
-1

use binding events for complex onclick functionality:

document.getElementById('anchorID').onclick=function(){/* some code */}

it will be easier for you. check out this fiddle: http://jsfiddle.net/anurag/amedr/

2 Comments

dunno :/ but if you think that is good answer, vote up please.
Well... I'm not going to upvote for the sake of cancelling theirs. I don't consider your answer good either though, because it's not complete in a sense enough for the poster to use, I only upvote good complete answers. I mostly just want to know why the down-voter considered it bad because the idea behind your answer is a correct one.

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.