swap div is only getting style:none value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Annuscha
    New Member
    • May 2012
    • 1

    #1

    swap div is only getting style:none value

    Hi,

    I'm been struggling with this for a week now, I'm new to javascript so please bear with me.

    What I have been trying to do is get the div to swap once you go over a <td>, at the moment the when you point on one of the <td> it takes the div away. My code gets data from the database, I have tested if it gets the right, and that is correct. I'm sure it's something in my javascript, I have a feeling it's got to do with this piece of code:

    Code:
    Code:
    if (arr[i].id != "navtxt" && arr[i].id.substr(0,5) != "style" && arr[i].id.substr(0,5) != "arrow" && arr[i].id != "" && arr[i].id != "mediaspace") {
    
                    arr[i].style.display = 'none';
    Here is the complete code:
    Code:
    <script language="javascript">
    
    function showDiv(elem)
    
    {
    
            var arr = document.getElementsByTagName('div')
    
            for(var i=0; i<arr.length;i++)
    
            {
    
                if (arr[i].id != "navtxt" && arr[i].id.substr(0,5) != "style" && arr[i].id.substr(0,5) != "arrow" && arr[i].id != "" && arr[i].id != "mediaspace") {
    
                    arr[i].style.display = 'none';
    
                    var styler = document.getElementById("style1_"+arr[i].id);
    
                    styler.className = "stylegray";
    
                    var styler = document.getElementById("style2_"+arr[i].id);
    
                    styler.className = "stylegray";
    
                }
    
            }
    
    
    
            var arr = document.getElementsByTagName('img')
    
            for(var i=0; i<arr.length;i++)
    
            {
    
                if (arr[i].id.substr(0,5) == "arrow") {
    
                    arr[i].src = 'images/blank.jpg';
    
                }
    
            }
    
    
    
            var arr = document.getElementsByTagName('a')
    
            for(var i=0; i<arr.length;i++)
    
            {
    
                if (arr[i].id.substr(0,7) == "style3_") {
    
                    var styler = document.getElementById(arr[i].id);
    
                    styler.style.color = "#e3e3e3";
                }
            }
    
            e2 = document.getElementById(elem);
    
            e2.style.display = 'block';
    
            e3 = document.getElementById("style1_"+elem);
    
            e3.className = "stylered";
    
            e3 = document.getElementById("style2_"+elem);
    
            e3.className = "stylegray2";
    
            e3 = document.getElementById("style3_"+elem);
    
            e3.style.color = "darkred";
    
            e3 = document.getElementById("arrow_"+elem);
    
            e3.src = "http://bytes.com/images/arrow.png";
    }
    
    </script>
    
    <table width="100%" border="0" cellpadding="0" cellspacing="0" style="word-wrap: break-word; table-layout: fixed; height: 130px">
    							<tr>
    							<?							foreach ($niceArray AS $key => $value) {
    
    							$i++;
    							$bstyle = "border-right-width: 2px; border-right-style: solid; border-right-color: #e3e3e3;";
    										if ($i == $numrows) {
    											$bstyle = "";
    										}
    										$color1 = "stylegray";
    										$color2 = "stylegray";
    										$color3 = "#e3e3e3";
    							$arrow = "http://bytes.com/images/blank.jpg";
    							if ($first) {
    							$first = false;
    							$firstDiv = $value["showDiv"];
    
    }
    ?>
    							<td align="left" style="<?=$bstyle?> padding-left: 10px; padding-right: 10px;" width="<?=$sizer?>%" onmouseover="javascript:showDiv('<?=$value["showDiv"]?>');"  valign="top">
    
    <center><img id="<?=$value["id"]?>" width="12px" height="12px" src="<?=$arrow?>" /></center>
    
    <br />
    
    <b>
    <div id='style1_<?=$value["showDiv"]?>' class="<?=$color1?>"><?=strtoupper($value["file_type"])?></div>
    </b>
    
    <br />
    
    <?php if ($value['file_type'] != 'Video') {?> <a id='style3_<?=$value["showDiv"]?>' href="<?=$value['click']?>" style="color: <?=$color3?>; text-decoration: underline; font-size:11px;" target="_blank">Click here to view</a> <? } ?>
    
    <br />
    <br />
    							<a href="javascript:showDiv('<?=$value["showDiv"]?>');">
    							<div id='style2_<? echo $value["showDiv"];?>'class="<?=$color2?>"><?=$value["file_name"]?></div>
    </a>
    
    <br />
    </td>
    <?}?>
    
    <script language="javascript">showDiv('<? echo $firstDiv;?>');
    </script>
    If someone could please point me in the right direction I would really appreciate it.

    Thanks
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Yes, that will set the display to none. I don't know what you question is.

    Comment

    Working...