Click to See Complete Forum and Search --> : Object linking....please HELP!!!!


Dudsmack
10-22-2003, 10:34 PM
I want to make a function that recieves a name of a variable...this variable (a string) will be equal to the name of a DIV object, and I want this function to return a link to the object.

syntax:
link = myFunction(menuObject);

example:
truckObject = myFunction(bigTruck);

Ideally it would set 'truckObject' to be equal to bigTruck.style.

Is there a way I can use the value of the string 'menuObject' to point directly to an object (a dhtml 'div' object)?? ...because if I just use menuObject.style it doesn't work.

thanx

Khalid Ali
10-22-2003, 11:00 PM
read up on eval() function at
devedge.netscape.net

Dudsmack
10-22-2003, 11:08 PM
eval() works with individual variables but not to the actual object. tosource() won't do the trick either.

Dudsmack
10-22-2003, 11:13 PM
Here's what I have:


function linkObject(objectName) {
if (canHandleDHTML())
{
if (document.layers) //Netscape-ish handling of dhtml objects
{
return document.eval(objectName);
}
else if (document.all) //Internet Explorer-ish handling of dhtml objects
{
return = (eval(objectName)).style;
}
}
}


eval isn't working it just errors up.

Khalid Ali
10-22-2003, 11:27 PM
No wonder you get errors..use the following function,I have nottested it,but it should work..

function linkObject(objectName) {
if (canHandleDHTML()){
if (document.layers){ //Netscape-ish handling of dhtml objects
return eval('document.layers['+objectName+'].style');
}else if (document.all){ //Internet Explorer-ish handling of dhtml objects
return = eval('document.all['+objectName+'].style');
}
}
}

Dudsmack
10-22-2003, 11:50 PM
That did it! In retrospect I can't believe I missed that! I've been working on my website trying to use dhtml and the lack of standards has been driving me nuts. This is going to make things much, MUCH nicer.

Thank you much kind sir!!

Khalid Ali
10-23-2003, 08:13 AM
no problem...glad that I could help