SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    creating a list of Frame's IDs

    Hi,

    I have an index page which has 2 frames, view & editor.

    Editor has a drop down menu (using select tag), i'm suppose to write a function to create a menu of view ids. I run the function in body tag using onload. not sure if it's right. & I can't figure out what is wrong with my code.

    Here is part of editor page code.
    Thanks in advance.


    Code HTML4Strict:
    <head>
     <script type = "text/javascript">
       <!--
     
    //This function gets a frame name and return an array of IDs in that frame.
     
    	function getElementIDs(frameName){
     
    	     var allTags = newArray();
    	     allTags =   window.frames['frameName'].document.body.getElementsByTagName("*");
     
    	     var ids = newArray();
    	     for (var tg = 0; tg< allTags.length; tg++) {
    	       var tag = allTags[tg];
    	       if (tag.id) {
    	       ids.push(tag.id);
    	       }
    	     }
    	  return ids;			
       }
     
           //create the drop down list, it gets the frame name and the select id
     
    	function addDropList(frameName,targetID){
     
    		var list = newArray();
    		list= getElementIDs(frameName);
     
    		var target= document.getElementById("targetID");
    		for(var i=0; i<list.length; i++){
    		 var o = document.createElement("option");
    		 o.value = list[i];
    		 o.text = list[i];
    		 target.add(o);					
    	       }
    	}
     
            //it function is supposed to run when the page is loaded. It creates the
            // drop list of view frame IDs.
         function my_load(){
    	   addDropList(view,sID);
    	}						
       //-->	
      </script>
    </head>
    	<body onload="my_load();">
    		<form>		
    			<p>
    			  <label> Please choose an element to edit:
    			 	<select name = "IDs" id="sID" >
    				<option></option>
    				</select>
    			   </label>
    	        </p>
    		</form>
    	</body>

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    In your function "my_load", you call addDropList with some arguments. Those arguments (view, sID) are both going to be undefined. You need to assign some values for them so that your functions work.

    You also have typos: it's "new Array()", not newArray. You don't need to use that anyway, you can just do this which also creates a new array:
    Code:
    var list = [];

  3. #3
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, I changed the array definition, and also my_load function a bit. still not working. here is my_load:

    Code JavaScript:
    function my_load(){
      var selectTag = document.getElementbByTagName("select"); 
      var selectId= selectTag.id; //get select id
     
      //get the all the tags in frameset in parent window 
      var frameTag=window.frames["view"].document.frameset.getElementByTag("*");
      var fIDs = [];
      //list all the frame tags in frameSet
      for (var fr = 0; fr < frameTag.length; fr++){                                                                
         var frm = frameTag[fr];
         if (frm.id) 
         fIDs.push(frm.id);
      }
      //get the if of first element in fIDs array			  
      var viewId = fIDs[0];
      addDropList(viewId, selectId);
    }

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You have typos there. Both instances of getElementsByTagName are wrong.

    You need to identify these before posting on here, as these are trivial things you can find out for yourself.

    If you don't have it, install Firebug for Firefox. It'll tell you if you have errors and on what line they are.

  5. #5
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks


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
  •