jtjohnston Posted August 22, 2006 Share Posted August 22, 2006 http://www.hak5.org/wiki/index.php?title=E...with_Javascript See " Div Tag Tricks with Javascript" fuction should be spelled function. Also, in Mozilla 1.7.13 I still get this error: Error: document.getElementByID is not a function Source File: file:///C:/WINDOWS/Bureau/Nouveau%20HTML%20Document.htm Line: 9 Did I miss something in the episode? John <HTML> <body><script language="javascript"> function showPage(id) { var totalNumberOfPages = 2; for( i = 1; i <= totalNumberOfPages; i++) { if(document.getElementByID('page'+i)) document.getElementById('page'+1).style.display='none'; } if(document.getElementById('page'+id)) document.getElementById('page'+id).style.display='block'; } </script> <div id="navigation"> <a href="java script:onClick=showPage('1')">page 1</a> <a href="java script:onClick=showPage('2')">page 2</a> </div> <div id="page1" style="display: none;">aa </div> <div id="page2" style="display: none;">bb </div> </body> </HTML> Quote Link to comment Share on other sites More sharing options...
jtjohnston Posted August 22, 2006 Author Share Posted August 22, 2006 Error: document.getElementByID is not a function if(document.getElementByID('page'+i)) Should be spelled: Id as in if(document.getElementById('page'+i)) not ID :P Quote Link to comment Share on other sites More sharing options...
Famicoman Posted August 22, 2006 Share Posted August 22, 2006 Does it work? I coppied that code from a very low quality version of the episode, and have no knowledge of javascript. Quote Link to comment Share on other sites More sharing options...
jtjohnston Posted August 22, 2006 Author Share Posted August 22, 2006 Does it work? I don't have much more knowledge. But you need to do this, IF you totalNumberOfPages is more than 2! var totalNumberOfPages = 3; for( i = 1; i <= totalNumberOfPages; i++) { // if(document.getElementById('page'+i)) // document.getElementById('page'+1).style.display='none'; // previous two lines do not work. document.getElementById('page'+i).style.display='none'; } These emoticons are making me much more nasty than I really am. It's a useful piece of JS, with a few repairs. I'm working on a tabbed menu page. I'll post an URL later. John Quote Link to comment Share on other sites More sharing options...
jtjohnston Posted August 22, 2006 Author Share Posted August 22, 2006 Might be useful to place totalNumberOfPages outside the function. Then again, I'm about to use totalNumberOfPages in another function. I'll post that after. var totalNumberOfPages = 3; function showPage(id) { for( i = 1; i <= totalNumberOfPages; i++) { // if(document.getElementById('page'+i)) // document.getElementById('page'+1).style.display='none'; // previous two lines do not work. document.getElementById('page'+i).style.display='none'; } if(document.getElementById('page'+id)) document.getElementById('page'+id).style.display='block'; } Quote Link to comment Share on other sites More sharing options...
jool Posted August 22, 2006 Share Posted August 22, 2006 There was an error in the code on the wikis that I fixed. Inside the loop that sets the display style to 'none' the element referenced should be page+i and not page+1. Kinda pointless to loop otherwise. And from a purely esthetic and standardized standpoint you should put script tags where you only define functions or load files inside the head tag. Quote Link to comment Share on other sites More sharing options...
jtjohnston Posted August 22, 2006 Author Share Posted August 22, 2006 Working on this for right now: http://jtjohnston.ca/test/tabbedmenu.html I have the Hak5 errors fixed for now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.