Creating a list of Frame's IDs

[B]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.[/B]

<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>	

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:

var list = [];

ok, I changed the array definition, and also my_load function a bit. still not working. here is my_load:

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);
}

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.

Thanks