plank@plank.com wrote:
Quote:
hey.. ok i need help! :(
>
let me try and describe my situation.. i have a javascript object which dynamically creates a div
element and uses ajax to call a page for the content of the div. Within this content i need to
reference a function which is defined in the javascript object which created the div. have i lost
anyone???
>
let me try and explain with some code:
>
function newDiv()
{
var oDiv = document.createElement("div");
oDiv.id = "div1";
document.body.appendChild(oDivMain);
>
function LoadMe(sURL)
{
myXMLReq = window.XMLHttpRequest ? new XMLHttpRequest() : new
ActiveXObject("Microsoft.XMLHTTP");
myXMLReq.onreadystatechange = URLRetreived;
>
var sPage = sURL;
var sParams = ""
var iPos = sURL.indexOf("?");
if (iPos -1)
{
sPage = sURL.substr(0, iPos);
sParams = sURL.substr(iPos + 1) + "&";
}
sParams += "winid=" + Me.WinID;
>
myXMLReq.open('POST', sURL, true);
myXMLReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
myXMLReq.send(null);
}
>
function URLRetreived()
{
if (myXMLReq.readyState == 4)
{
if (myXMLReq.status == 200)
{
var oMeDiv = document.getElementById("div1");
oMeDiv.innerHTML = myXMLReq.responseText;
}
else
{
document.getElementById("div1").innerHTML = "ERROR";
}
}
}
>
function testFunction()
{
alert("hello world");
}
}
>
var obj = new newDiv();
obj.LoadMe("hello.htm);
>
>
>
hello.htm:
>
<a href="testFunction();">click me</a>
>
>
>
>
How can i reference the testFunction defined in the object?
>
I hope that makes sense!
>
Thanks in advance,
>
ajb
This should also work...
function newDiv()
{
this.testFunction = function()
{
alert("hello world");
}
}
var obj = new newDiv();
obj.testFunction;
'this' refers to the object itself, and is in effect, the actual
object. newDiv.testFunction() and using the new object we made
obj.testFunction() (I think), will both translate to
this.testFunction(). so testFunction() will be called from within the
appropriate object.
I hope that helps and makes sense as I think I have confused myself. If
anyone could clarify what I have written, it would be appreciated and
help me a great deal also.
All the best.
Daz.