By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,287 Members | 1,561 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,287 IT Pros & Developers. It's quick & easy.

Stuck for several days

P: n/a
Hello, first of all it's convenient to say that I'm not an expert, neither
nothing similar, just in case. I have been trying to execute this little
piece of code with no results, does anyone there can detect where the bug
is:

var labelsArray = new Array(6);

----------------------------------------------------------------------------
----------------
function objCreation()
{
for (i=0; i < labelsArray.length; i++)
{
var labelObj = {labelID:
"document.getElementById('Label"+i+"').filters.alp ha.opacity"};
labelsArray[i] = labelObj;
}
}

function over(no)
{
eval(labelsArray[no].labelID = 20);
}

----------------------------------------------------------------------------
---------------

Basically, the function objCreation creates 6 objects with only one
attribute (labelID) each one and stores it into an Array called labelArray
Then the function over(no) is loaded when the MouseOver event takes place.
The problem is that since
labelsArray[no].labelID is equal to the string
document.getElementById('Label0').filters.alpha.op acity for example, it is
not recognized as a functional statement, as a result it doesn't do anything
if I assign the value 20 in this case.

The website is at : http://new.vanara.com/ , if someone wants to see it.

Thanks in advance,
Javier.
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Javier Troconis" <tr******@telus.net> wrote in message
news:0hmWb.54292$7Q1.9039@clgrps12...
<snip>
var labelsArray = new Array(6); <snip> function objCreation()
{
for (i=0; i < labelsArray.length; i++)
{
var labelObj = {labelID:
"document.getElementById('Label"+i+"').filters.alp ha.opacity"};
labelsArray[i] = labelObj;
}
}

function over(no)
{
eval(labelsArray[no].labelID = 20);
If you are not an experienced javascript programmer and you are using
the - eval - function you can be certain that you are doing something
fundamentally wrong.

<URL: http://jibbering.com/faq/#FAQ4_40 >
}

<snip>

You have omitted one very important detail and that is why. Why jump
through such hoops and use such a convoluted method? When on the face of
it your entire posted code could be replaced with:-

function over(no){
document.getElementById('Label"+no).filters.alpha. opacity = 20;
}

- and achieve your apparent goal in the browsers where it will work.
Or:-

function over(no){
var obj;
if((document.getElementById)&&
(obj = document.getElementById('Label"+no))&&
(obj.filters)&&
(obj.filters.alpha)){
obj.filters.alpha.opacity = 20;
}
}

- Which achieves the same but won't error on the majority of web
browsers in the way the previous version and your original code was
destined to.

Richard.
Jul 20 '05 #2

P: n/a
"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message
news:c0*******************@news.demon.co.uk...
<snip>
function over(no){
document.getElementById('Label"+no).filters.alpha. opacity = 20; ^ ^
document.getElementById("Label"+no).filters.alpha. opacity = 20;}

<snip>

Except in both cases it will work better with the same type of quote
marks on each side of the string literal.

Richard.
Jul 20 '05 #3

P: n/a
Richard Cornford wrote:
"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message
news:c0*******************@news.demon.co.uk...
<snip>
function over(no){
document.getElementById('Label"+no).filters.alpha. opacity = 20;

^ ^
document.getElementById("Label"+no).filters.alpha. opacity = 20;
}

<snip>

Except in both cases it will work better with the same type of quote
marks on each side of the string literal.

Richard.


True, that often helps a lot. :P
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.