...

View Full Version : 2 values in one var ?



Jesper Møller
08-09-2006, 11:15 PM
I have this small script for removeing the "focus box" arund link:

function RemoveLinkbox() {
var aA = document.getElementsByTagName("a");
for (var i=0,j=aA.length;i<j;i++) aA[i].onfocus = function(){this.blur()};
}

I woud like the script to also remove the "focus box" around areas in imagemaps. so i did this:

function RemoveLinkbox() {
var aA = document.getElementsByTagName("a");
for (var i=0,j=aA.length;i<j;i++) aA[i].onfocus = function(){this.blur()};
var aAr = document.getElementsByTagName("area");
for (var i=0,j=aAr.length;i<j;i++) aAr[i].onfocus = function(){this.blur()};
}


I was thinking if it is posible to make the "var aA" to have both "a" and the "area" in the same line/funktion ??
Somthin like:

var aA = document.getElementsByTagName("a") || document.getElementsByTagName("area");

:confused:

brandonH
08-10-2006, 02:52 AM
not sure exactly what you're asking for... are you trying to assign two values to one var? if so may i ask why you're not using two variables?

from what i get of what you're asking for, you want your var aA to have two values. may i ask another question... what exactly are you trying to acomplish by doing this? if i had an understanding of what you want as an end result i would be much more able to help.

brandonH
08-10-2006, 03:00 AM
was thinking and thought that maybe you wanted the function to perform it operation of both 'a' and 'area'. if so then its simple.



function Remove(tag){
var aA=document.getElementById(tag);
for (var i=0,j=aA.length;i<j;i++) aA[i].onfocus = function(){this.blur()};
}


then all you have to do is call the function 2 times:

Remove('a');Remove('area');

Jesper Møller
08-10-2006, 06:14 AM
Thanks brandon

Yes ... i want it to preform the action on both "a" and "area"
But the tricky part is... I cant call it 2 times... Only one time with this <body onload="CSScriptInit();">
It calls al my actions

so the script jas to work without setteing the var's.. they shud bee in the script

brandonH
08-10-2006, 07:48 AM
what is keeping you from calling the function twice? you can run more than one function with onload. or are you just wanting to run the one function, and have everything else run off of it? in that case just call the remove function 2 time from within the CSScriptInit() function.

felgall
08-10-2006, 09:25 AM
When you want to store more than one value in a variable at the same time you should create an array.

Jesper Møller
08-10-2006, 10:26 AM
"what is keeping you from calling the function twice?"

The CSScriptInit() is caling the function, infact all functions is calld by this.
(Its not so easy to explain)

Stephen >>

Why din't i think of that ?
I think i got it now :-)


var aA=["a","area"];for(i=0;i<aA.length;i++)for(j=0;aAr=document.getElementsByTagName(aA[i])[j];j++)aAr.onfocus=function(){this.blur()};

Thanks ;-)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum