By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,426 Members | 2,753 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,426 IT Pros & Developers. It's quick & easy.

Change object values using an array

P: 1
Greetings folks,

I have been trying for sometime now to figure out what I am sure is this very simply problem. I have been unscuessful in finding the answer though so if anyone can help I would definitely appreciate it.
Below is the code I am using, however it doesn't work for me and I know it is coming from the code inside the for loop as it works when I remove the code and write this manualy.

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" ><!--
  2.  
  3. var objname = new Array (3);
  4. var ifrmname = new Array (3);
  5.  
  6. objname[0] = document.getElementById("objframe1");
  7. objname[1] = document.getElementById("objframe2");
  8. objname[2] = document.getElementById("objframe3");
  9.  
  10. ifrmname[0] = "MAIN1";
  11. ifrmname[1] = "MAIN2";
  12. ifrmname[2] = "MAIN3";
  13.  
  14.     **function ViewIFRAME(framename, iframe_val) {
  15.  
  16.         for (var loop = 0; loop < objname.length; loop++){
  17.  
  18.             document.getElementByName(objname[loop]).style.display = "none";
  19.         }        
  20.  
  21.         document.getElementById(iframe_val).style.display = "";
  22.         document.getElementById(framename).style.display = "";
  23.     }
  24.  
  25.     function HideIFRAME(framename, iframe_val) {
  26.  
  27.         document.getElementById(iframe_val).style.display = "none";
  28.         document.getElementById('objframe').style.display = "none";
  29.  
  30.     }
  31. //-->
  32. </script>
The code is apart of a larger script I am writing which will allow users to togle between 3 built in IFRAMES within my page.

Thanks in advance,
Feb 3 '08 #1
Share this Question
Share on Google+
1 Reply


gits
Expert Mod 5K+
P: 5,333
hi ...

the method is called getElementsByName and returns you a node list ... so why don't you use an id?

kind regards
Feb 4 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.