SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Addict ibeblunt's Avatar
    Join Date
    Jan 2001
    Location
    Jersey City, NJ
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing A Variable In Javascript

    I came up with this javascript to highlight an area, and I can't figure out why it's not working:

    Code:
    <script language="JavaScript" type="text/javascript">
    <!--
    function menu(area) {
    
    	if (area) {
    	
    		onLoad=area.style.backgroundColor='#eeeeee';
    
    	}
    		
    	return;
    	
    }
    //-->
    </script>
    
    <body onLoad="menu('home');">
    How do I get the area variable to be put place? Like:

    onLoad=home.style.backgroundColor='#eeeeee';

    Thanks
    <///////~

    www.sohh.com

  2. #2
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tested this and it works on IE 5, NS 4, and NS6/Mozilla:

    Code:
    function menu(id) {
    	var styleObj = getLayerStyle(id);
    	if (typeof(styleObj) != "undefined") {
    		if (document.layers)
    			styleObj.bgColor = '#000';
    		else styleObj.backgroundColor = '#000';
    		}
    }
    
    function getLayerStyle(id){
    	if (document.getElementById) return document.getElementById(id).style;
    	else if (document.all) return document.all[id].style;
    	else if (document.layers) return document.layers[id];
    }
    ck :: bringing chris to the masses.


Bookmarks

Posting Permissions

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