Web Analytics Made Easy -
StatCounter passing parameter in window.onload function - CodingForum

Announcement

Collapse
No announcement yet.

passing parameter in window.onload function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • passing parameter in window.onload function

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script>
    window.onload = function(){h = parseInt(document.getElementById("div1").style.height);}
    
    var t;
    
    function addHeight(openAccordionID){
    	clearInterval(t);
    	document.getElementById(openAccordionID).style.height = h+"px";
    	h+=1;
    	t = setInterval("addHeight('"+openAccordionID+"')",10);
    	for(var x=1; x<h; x++)
    	if(h%(x*100)==0){clearInterval(t);}
    	}
    
    </script>
    
    </head>
    <body>
    
    <div id="div1" onclick="addHeight(this.id)" style="width: 200px; height: 20px; background-color: yellow;">Increase Height</div>
    
    </body>
    </html>
    How can I still use the parameter "openAccordionID" in the blue-highlighted part? I tried, but it failed.

  • #2
    Why would you want to do that?

    Comment


    • #3
      Originally posted by devnull69 View Post
      Why would you want to do that?
      Just to make sure that whenever I use this script as a template, I only need to change the parameter in the JS part. Need not to go to HTML and JS to change both of the entries for the element ID.

      Comment


      • #4
        There is no way around this other than keeping it "div1". As soon as you change it in HTML you need to change it in Javascript too. Otherwise window.onload will not know about the element you are referring to

        Other than your onclick it has not been initiated by the element.

        Comment


        • #5
          I see. Thanks. If JS does not allow this, I will not search the solution and spare the time on other stuff of JS.

          Comment

          Working...
          X