Click to See Complete Forum and Search --> : Array behaviour in opera


justin001
10-23-2003, 08:49 AM
The following line of code works 100% in IE, but gives a value of warning when I try to display the array in an alert box in opera, and the length has a value of NaN.

menuRef.length=eval(pPos)+1;

Basically what I am doing is converting the length of the array menuRef relative to pPos which is always passed and always positive whole number. Do arrays in Opera not support dynamic length changing?

Khalid Ali
10-23-2003, 09:23 AM
your error in my opinion is here
eval(pPos)

whats the value in pPos,do you know that you need eval here?
why are you using eval here?
why couldn't you just do this(if pPos is a number)

menuRef.length=pPos+1;

justin001
10-23-2003, 09:28 AM
Hi Khalid

Thanks for your input and sorry for wasting your time, but I have been backtracking further in my code and I found the REAL problem is something else:

function findCurrPointer(pCurrElement)
{
for (var i=pCurrElement;i.tagName!="BODY";i=i.parentElement)
if (i.className=="menuCellOut"||i.className=="menuCellOver")
{alert (i.name);return i}
return false;
}

The above is a function (that works) that steps up through the DOM by following the tree of parent elements. no problem there. The problem is when the function stops and returns an object. This object is a TD tag with a name of 1, 2 or 3, depending on which cell I am referring to. I can't reference this name, it always is undefined. Yet in IE, the name is there and referencable, clear as day. I CAN access classname, so far. Haven't tried any other properties. What's up with that? Thanks in advance...

Khalid Ali
10-23-2003, 09:31 AM
show me the HTML part,or better yet,post a link to the actaul page

justin001
10-23-2003, 09:45 AM
Unfortunately I ca't ive you the whole page, but here's the code and the HTML and style. Haven't tried but it should be plug and playable. Thanks for taking a look, I really appreciate it...

Khalid Ali
10-23-2003, 10:35 AM
Check this link out,I am not sure this is how it was suppose to work...if its not then zip one full file that actually works at least...( I can't spend too much time first to make it work and then find out whats your problem in it)

http://68.145.35.86/temp/justin001/HTML.html

and let me know what would it look like in IE and whats that its not doing in Opera

justin001
10-24-2003, 01:24 AM
Hey Khalid. Sorry about the posting delay, just got back into work now. I am about to have a look at teh script you put together. I really do appreciate all the help. Unfortunately I cannot post the whole page, because it is for a client and my company is not happy posting that kind of information on a forum. But I'll get back to you as soon as I've checked out the code.

Thanks again :)
Justin

justin001
10-24-2003, 01:52 AM
For some reason I can't get the link to resolve... Anyway the problem with my code is, I'm pretty sure, not the code itself, but Opera's functionality. I ran the following function to test a DIV for it's properties and methods, and got two very different outputs from Opera and IE. IE returned the usual name, id, className, etc... but Opera only returns functions. This is strange. If I try to get the name of the DIV I wrote I get undefined in OPera, but "happy" in IE... Very weird! Any ideas?

<html>
<head>
<script>
function showStuff()
{
var content="";
for (var i in document.getElementById("happier"))
content+=i+": "+document.getElementById("happier")[i]+"<br>";
document.write(content);
}
</script>
</head>
<body onclick="showStuff();">
<div style="border: 1px solid black;" name="happy" id="happier">
Hi
</div>
</body>
</html>

IE OUTPUT:
language:
scrollHeight: 21
isTextEdit: false
currentStyle: [object]
document: [object]
onmouseup: null
oncontextmenu: null
isMultiLine: true
clientHeight: 0
onrowexit: null
onbeforepaste: null
onactivate: null
scrollLeft: 0
lang:
onmousemove: null
etc...

OPERA OUTPUT:
toString: function toString() { [native code] }
focus: function focus() { [native code] }
blur: function blur() { [native code] }
insertAdjacentText: function insertAdjacentText() { [native code] }
insertAdjacentHTML: function insertAdjacentHTML() { [native code] }
insertAdjacentElement: function insertAdjacentElement() { [native code] }
removeNode: function removeNode() { [native code] }
setAttributeNodeNS: function setAttributeNodeNS() { [native code] }
getAttributeNodeNS: function getAttributeNodeNS() { [native code] }
removeAttributeNode: function removeAttributeNode() { [native code] }
setAttributeNode: function setAttributeNode() { [native code
etc..

justin001
10-24-2003, 05:12 AM
I made a workaround to the script for Opera and it works now. Thanks to all those who helped. I really appreciate it. I am still slightly baffled about the problem with opera though. I assumed all attributes in a tag were accessible through javascript.

Thanks,
Justin

Khalid Ali
10-24-2003, 08:37 AM
glad it worked out for you..:p

justin001
10-25-2003, 12:41 AM
Thanks again Khalid - u've been a big help. For those who're interested -- a workaround to the Opera problem:

From another forum.., poster aleto:

To get a attribut you need the getAttribute(atr) function. For example for this page:



code:--------------------------------------------------------------------------------
java script:alert(document.getElementById("logo").getAttribute("src"))
--------------------------------------------------------------------------------


( to test just typ it in the addressfield, without the space bar between java and script )