Jump to content

Error: Div Tag Tricks with Javascript


jtjohnston

Recommended Posts

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>

Link to comment
Share on other sites

Does it work?

I don't have much more knowledge. But you need to do this, IF you totalNumberOfPages is more than 2! :lol:

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

Link to comment
Share on other sites

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

}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...