the answer is here onclick=\"" + this.instance + ".getName()\">"
by passing the name of the prototype instance into, or as part of the function, the click knows where its supposed to be going to do what it needs to do so in effect the onclick for the link would look like onclick="myTabs.getName()" that's the only way your going to be able to do it, otherwise it doesn't know what the hell "this" is or where the doMakeActive function is. the only way it will know is to know the instance of the prototype cause that's where the function actually is. its not a global document function as it would be if your function was just on the page somewhere Steve -----Original Message----- From: [email protected] [mailto:[EMAIL PROTECTED] Behalf Of Taco Fleur Sent: Wednesday, February 22, 2006 4:54 PM To: [email protected] Subject: [cfaussie] Re: [OT] Reference to JS object Sorry I can't see the solution in there. I am very well aware that what = alert( '' ); would evaluate immediately, if you look at my first sample you will see that I have it within quotes. I think what I want to do just can't be done, and I have to write the function outside the object. On 2/22/06, Steve Onnis <[EMAIL PROTECTED]> wrote: > > you cant do it like that taco > > if you have > myListItem.onclick = "alert('hello');"; > > you will see the list item gets populated with the alert > > if you have > myListItem.onclick = "alert(this);"; > > it uses the object, in your case the <li> element as what "this" is, not the > prototype object > > you cant have > myListItem.onclick = alert(this); > > because the alrt will run when the function is run, just like whats > happening with your function. > > with your prototype, you cant just reference "this" in your function as > though it was still part of the prototype. > > your onclick needs to have a reference to the prototype so it knows which > instance it needs to work with > > /////////////////////////////////// > <script> > > function tab() { > this.instance = arguments[0]; > this.tabs = new Object(); > } > > tab.prototype.addTab = function (label, link) { > this.tabs[label] = new Object(); > this.tabs[label].label = label; > this.tabs[label].link = link; > > } > > tab.prototype.getName = function () { > alert(this.instance); > } > > tab.prototype.writeTabs = function () { > var htmlStr = "<table><tr>"; > for (p in this.tabs) { > htmlStr = htmlStr + "<td><a href=\"" + this.tabs[p].link + "\" > onclick=\"" + this.instance + ".getName()\">" + this.tabs[p].label + > "</a></td>"; > } > htmlStr = htmlStr + "</tr></table>"; > return htmlStr; > } > > myTabs = new tab("myTabs"); > myTabs.addTab("tab 1", "index.cfm"); > myTabs.addTab("tab 2", "index.cfm"); > myTabs.addTab("tab 3", "index.cfm"); > myTabs.addTab("tab 4", "index.cfm"); > > document.write(myTabs.writeTabs()); > </script> > //////////////////////////////////////// > > just a quick example > > you need to let the onclick know what its suposed to be doing. > > > > > -- Taco Fleur - http://www.pacificfox.com.au Web Design, Web development, Graphic Design and Complete Internet Solutions an industry leader with commercial IT experience since 1994 … --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "cfaussie" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie -~----------~----~----~----~------~----~------~--~---
