SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: OK, I blew it!

Threaded View

  1. #1
    SitePoint Zealot matches's Avatar
    Join Date
    Aug 2006
    0 Post(s)
    0 Thread(s)

    OK, I blew it!

    I should have just posted my real problem rather than a mocked up version of it. Here is my original post:

    Anyway, in my real world situation. I have this CMS that I am using to monitor my front door. What I am trying to do is loop through all of the div ids and add an onclick to all the a tags within that div. on line 15, the alert() is added to the link. The reference to the mboxes array is undefined because for some reason the value of i is not available.

    What am I doing wrong?

    Thanks a lot!

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "">
    		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    		<title>Untitled Document</title>
    		<script type="text/javascript">
    			function start(){
    				var pageSections = ["header", "candy_cane", "left-column", "featured_products", "shoppingPicks"];
    	      var mboxes = ["FDmonitorTopNav", "FDmonitorPromo", "FDmonitorLeftNav", "FDmonitorFeaturedProducts", "FDmonitorBlogListings", "FDmonitorTopProducts"]
            for (var i=0; i < pageSections.length; i++) {
              var elementLink = document.getElementById(pageSections[i]).getElementsByTagName('a');
              for (var x=0; x < elementLink.length; x++) {
              elementLink[x].onclick = function()
                alert('MS-FDmonitor', mboxes[i]);
    	<body onload="start()">
    		<div id="header">
    			<a href="#">test</a>
    		<div id="candy_cane">
    			<a href="#">test</a>
    		<div id="left-column">
    			<a href="#">test</a>
    		<div id="featured_products">
    			<a href="#">test</a>
    		<div id="shoppingPicks">
    			<a href="#">test</a>
    Last edited by matches; Nov 9, 2007 at 17:16. Reason: I had a 0 in an assignment (var elementLink = document.getElementById(pageSections[i]).getElementsByTagName('a');)


Posting Permissions

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