Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder Jesper Møller's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Copenhagen
    Posts
    135
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Question 2 values in one var ?

    I have this small script for removeing the "focus box" arund link:
    Code:
    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:
    Code:
    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:
    Code:
    	var aA = document.getElementsByTagName("a") || document.getElementsByTagName("area");
    "True knowledge exists in knowing that you know nothing."

    "Education is learning what you didn't even know you didn't know!"

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    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.
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #3
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    was thinking and thought that maybe you wanted the function to perform it operation of both 'a' and 'area'. if so then its simple.

    Code:
    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');
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #4
    Regular Coder Jesper Møller's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Copenhagen
    Posts
    135
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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
    "True knowledge exists in knowing that you know nothing."

    "Education is learning what you didn't even know you didn't know!"

  • #5
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    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.
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,454
    Thanks
    0
    Thanked 632 Times in 622 Posts
    When you want to store more than one value in a variable at the same time you should create an array.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #7
    Regular Coder Jesper Møller's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Copenhagen
    Posts
    135
    Thanks
    9
    Thanked 0 Times in 0 Posts
    "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 :-)

    Code:
    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 ;-)
    "True knowledge exists in knowing that you know nothing."

    "Education is learning what you didn't even know you didn't know!"


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •