PDA

View Full Version : document.getElementById(cis) has no properties



requiem
11-19-2005, 06:06 PM
DD Tab Menu II
http://dynamicdrive.com/dynamicindex1/ddtabmenu2.htm

I am getting an error running on the script listed above. The error I'm getting is saying:

document.getElementById(cis) has no properties

Here is the code related to this error. Italicized is the only part of this code that refers to 'cis'. I did place the second portion of the code as well, but there is also no mention of 'cis' there either. I thought at first this had to do with a tag needing to have an id of cis but I really have no idea why this error keeps popping up. Any help would be much appreciated.

Thanks guys.

<script type="text/javascript">
/***********************************************
* DD Tab Menu II script- Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
//Set tab to intially be selected when page loads:
//[which tab (1=first tab), ID of tab content to display]:
var initialtab=[1, "sc1"]
//Turn menu into single level image tabs (completely hides 2nd level)?
var turntosingle=0 //0 for no (default), 1 for yes
//Disable hyperlinks in 1st level tab images?
var disabletablinks=1 //0 for no (default), 1 for yes
var previoustab=""

function expandcontent(cid, aobject){
if (disabletablinks==1)
aobject.onclick=new Function("return false")
if (document.getElementById && turntosingle==0){
highlighttab(aobject)
if (previoustab!="")
document.getElementById(previoustab).style.display="none"
document.getElementById(cid).style.display="block"
previoustab=cid
}
}


function highlighttab(aobject){
if (typeof tabobjlinks=="undefined")
collectddimagetabs()
for (i=0; i<tabobjlinks.length; i++)
tabobjlinks[i].className=""
aobject.className="current"
}
function collecttabs(){
var tabobj=document.getElementById("tabs")
tabobjlinks=tabobj.getElementsByTagName("A")
}
function do_onload(){
collecttabs()
expandcontent(initialtab[1], tabobjlinks[initialtab[0]-1])
}
if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload
</script>

Twey
11-19-2005, 06:23 PM
No mention of "cis" there. It's "cid."

requiem
11-19-2005, 06:36 PM
In reply to the...

No mention of "cis" there. It's "cid."

Yes, I'm a moron...I meant the error is:

document.getElementById(cid) has no properties

Anywhere I mentioned cis replace with cid.

Twey
11-19-2005, 06:47 PM
Ah, OK. What does the tag look like where you use expandcontent()?

requiem
11-19-2005, 06:50 PM
In the javascript...



function expandcontent(cid, aobject){
if (disabletablinks==1)
aobject.onclick=new Function("return false")
if (document.getElementById && turntosingle==0){
highlighttab(aobject)
if (previoustab!="")
document.getElementById(previoustab).style.display="none"
document.getElementById(cid).style.display="block"
previoustab=cid
}
}



In the HTML...



<a href="#" onMouseover="expandcontent('LINK1', this)">Link1</a> | <a href="#" onMouseover="expandcontent('LINK2', this)">Link2</a> | <a href="#" onMouseover="expandcontent('LINK3', this)">Link3</a> | <a href="http://url/" onMouseover="expandcontent('LINK4', this)">Link4</a> | <a href="" onMouseover="expandcontent('LINK5', this)">Link5</a>
</div>
<div id="Navcontainer">
<div id="LINK1" class="tabcontent">
<a href="#" target="_self" id="cid">SubLink1</a> | <a href="#" target="_self" >SubLink2</a> | <a href="#" target="_self" >SubLink3</a>
</div>
<div id="LINK2" class="tabcontent">
<a href="#" target="_self" >SubLink4</a> | <a href="#" target="_self" >SubLink5</a> | <a href="#" target="_self" >SubLink6</a>
</div>
<div id="LINK3" class="tabcontent">
<a href="#" target="_self" >SubLink7</a> | <a href="#" target="_self" >SubLink8</a> | <a href="#" target="_self" >SubLink9</a>
</div>
<div id="LINK4" class="tabcontent">
<a href="#" target="_self" >SubLink10</a> | <a href="#" target="_self" >SubLink11</a> | <a href="#" target="_self" >SubLink12</a>
</div>
<div id="LINK5" class="tabcontent">
<a href="#" target="_self" >SubLink13</a> | <a href="#" target="_self" >SubLink14</a> | <a href="#" target="_self" >SubLink15</a>

Twey
11-19-2005, 07:05 PM
Is that last div ever closed?

requiem
11-19-2005, 07:12 PM
Yes, the last div is closed. The thing I find hard to figure out is what 'cid' is for. I don't show it listed as any id anywhere. If I knew what part of the code the cid was for I would at least know where to look for the error.

This bold line is the specific line that is giving the error in the browser.

function expandcontent(cid, aobject){
if (disabletablinks==1)
aobject.onclick=new Function("return false")
if (document.getElementById && turntosingle==0){
highlighttab(aobject)
if (previoustab!="")
document.getElementById(previoustab).style.display="none"
document.getElementById(cid).style.display="block"
previoustab=cid
}
}

Twey
11-19-2005, 07:17 PM
The part of the code you have there is the only part that has access to cid, for a start, as it's a function argument. The place to look for the error is in your HTML, as you've pasted it above. The first argument you're passing to expandcontent() (at some point) isn't valid. Do you have a line/character reference, or could you provide a link to the page in question?

requiem
11-19-2005, 07:28 PM
http://homepages.wmich.edu/~j2willi4/schoolcraft

That is a link to the page that has the error. I did figure it had to do with the HTML in reference to an id that would have been cid, but since that is not the problem, that's why I'm having the issue.

Twey
11-19-2005, 07:38 PM
Aha.
The problematic ID is here:

//Set tab to intially be selected when page loads:
//[which tab (1=first tab), ID of tab content to display]:
var initialtab=[1, "sc1"]Element with ID "sc1" obviously doesn't exist. If you don't want a tab to open initially, simply find and remove the following line:
expandcontent(initialtab[1], tabobjlinks[initialtab[0]-1])
It's in do_onload().

requiem
11-19-2005, 07:46 PM
Awesome. It works, thank you very much Twey.

And just to clarify that I understand what you're saying. B/c sc1 hasn't been selected you basically cannot have it initially selected...that being because it doesn't exist until it is selected?

Twey
11-19-2005, 07:50 PM
No... you can't have it initially selected, quite simply, because there is no element with the ID "sc1."

requiem
11-19-2005, 08:02 PM
Okay, yes, I understand now. I had been looking at a bunch of other scripts trying to figure out this issue and saw others using sc1 and forgot it wasn't in the script I was using.

Thank you again though, I really appreciate it.