Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jan 2003
    Thanked 0 Times in 0 Posts

    Using onclick to define variable

    I have a page that has a map of the united states. You can click on any of the fifty states and it causes that state's hidden <div> to become visable. In each of the states <div>'s are a javascript that calls out for links relevant to that state.

    That all works fine, BUT having all fifty div's and the fifty different hidden javascript calls causes loading to be painfully slow.

    What I would like to do is have the onclick function that triggers a div to become visible to also delare a variable that can tell it which javascript taht div should call - so there is only one call loaded in the beginning and then a new one loads whenever a layer is made visible.

    Does this make sense? I will include the various bits of code below.

    Here is what I am using to cause the show/hide layer function:
    <script LANGUAGE="JavaScript" type="text/javascript">
    <!-- Hide from JavaScript-Impaired Browsers
    function MM_findObj(n, d) { //v4.01

    var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

    if(!x && d.getElementById) x=d.getElementById(n); return x;


    function MM_showHideLayers() { //v3.0

    var i,p,v,obj,args=MM_showHideLayers.arguments;

    for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];

    if (obj.style) { obj=obj.style; v=(v=='show')?'visible'v='hide')?'hidden':v; }

    obj.visibility=v; }




    And the onclick command that triggers the <div> to become visible:
    onClick="javascript:MM_showHideLayers('wa','','hide','or','','hide','ca','','show','nv','','hide','a z','','hide','ut','','hide','id','','hide','mon','','hide','co','','hide','nd','','hide','sd','','hi de','ks','','hide','min','','hide','nb','','hide','iw','','hide','ms','','hide','ok','','hide','tx', '','hide','ls','','hide','ak','','hide','mis','','hide','ab','','hide','wis','','hide','il','','hide ','mich','','hide','in','','hide','ky','','hide','ten','','hide','fla','','hide','ga','','hide','sc' ,'','hide','nc','','hide','va','','hide','wv','','hide','oh','','hide','pa','','hide','mas','','hide ','del','','hide','ri','','hide','ny','','hide','my','','hide','nj','','hide','con','','hide','vt',' ','hide','nh','','hide','maine','','hide','ala','','hide','hi','','hide','nm','','hide','wy','','hid e')">

    ---So if you clicked on the href you would make the <div id="ca"> become visible.

    Here is what the <div>'s look like:

    <div id="ca" style="position:absolute; width:334px; height:143px; z-index:1; left: 203px; top: 257px; overflow: auto; visibility: hidden">
    <td>California headlines

    <script language="JavaScript" src="EXTERNAL LINK"></script>


  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Thanked 256 Times in 252 Posts
    Put all the states and the corresponding description in a "hash array"
    var states = new Array();
    states["wa"] = "description here";
    states["ca"] = "description here";
    states["nv"] = "description here";
    //and so on...

    then just have 1 div that will contain the description of the clicked state.

    <div id="desc"></div>

    then on each onclick, get the corresponding description based on the abbreviated state from the array.


    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins


    Posting Permissions

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