iEntry 10th Anniversary Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > JavaScript

Reply
 
LinkBack Thread Tools
Old June 16th, 2009, 06:46 AM   #1
New Member
 

Join Date: Jun 2009
Location: PH
Age: 24
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 sircheel is on a distinguished road
Unhappy show/hide div not working on IE if onload="showdiv();" is used

Hi, i have this jscript code and I want to show the first div onLoad. Trying to figure this out, what I did was:

<body onload="showdiv(0);">

Running on firefox works fine, the first div is showing onload BUT testing on IE doesn't work at all. It displays an error:

document.getElementById()is null or not an object

here's the jscript i'm using:
<script type="text/javascript">

var c;
var k=0;
var j=0;
var ary=[];
var divs=document.getElementsByTagName('div');
var lnks=document.getElementsByTagName('a');
var splt;

function init() {
for(c=0;c<divs.length;c++) {
if(divs[c].className=='show') {
divs[c].className='hide';
divs[c].id='d'+k++;
}
}
for(c=0;c<lnks.length;c++) {
if(lnks[c].className=='hide') {
ary[c]=true;
lnks[c].className='hs';
lnks[c].id='a'+j++;
lnks[c].onclick=function() {
splt=this.id.split('a')[1];
if(ary[splt]==true) {
this.firstChild.nodeValue='hide '+(parseFloat(splt)+1);
ary[splt]=false;
showdiv(splt);
return false;
}
else {
this.firstChild.nodeValue='show '+(parseFloat(splt)+1);
ary[splt]=true;

document.getElementById('d'+splt).className='hide' ;
return false;
}
}
}
}
}


function showdiv(num) {
for(c=0;c<j;c++){
document.getElementById('a'+c).firstChild.nodeValu e='show '+(c+1);
document.getElementById('a'+num).firstChild.nodeVa lue='hide '+(parseFloat(num)+1);
ary[c]=true;
ary[num]=false;
}
for(c=0;c<divs.length;c++) {
if(divs[c].className=='show') {
divs[c].className='hide';
}
}
document.getElementById('d'+num).className='show';<--- this is the line error
}

if(window.addEventListener){
window.addEventListener('load',init,false);
}
else {
if(window.attachEvent){
window.attachEvent('onload',init);
}
}

</script>


How will i solve this issue? So frustrating...
Hope someone can take a peek on my codes.
sircheel is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old June 17th, 2009, 10:13 AM   #2
Reputable Member
 

Join Date: Nov 2008
Location: Lexington, KY
Posts: 243
Thanks: 0
Thanked 1 Time in 1 Post
Rep Altering Power: 0 Dubbs is on a distinguished road
Re: show/hide div not working on IE if onload="showdiv();" is used

Looking at your code the variable D isn't defined anywhere in the script. You may want to see if adding var d =0 at the top of your code solves the issue.
Dubbs is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a "tag" system to find relevant "related" pages MrQuestions PHP 3 March 20th, 2008 09:06 PM
[SOLVED] Show "Image" Depends On User "Status"? Monie Classic ASP 6 October 15th, 2007 10:22 PM
? IS "meta name="robots" content="?" necessary in pages ? Love2Java Your Design and Layout 6 August 8th, 2007 10:48 AM
Can't Get Table Background to show when "E-Mailing" Page chriss HTML, XHTML and CSS 5 May 8th, 2007 11:10 AM
window.opener.document["nameForm"].getElementById("someid").value; doesnt work drpompeii JavaScript 0 February 17th, 2007 08:09 PM


Search Engine Optimization by vBSEO 3.2.0 RC8