PDA

View Full Version : two level menu problem


xiaodao
07-15-2008, 03:12 AM
Hi,

i used this menu script from dynamic drive and modified slightly, but the problem is weird, it does not show the correct 2nd level menu

detailed code below

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>


<style>
/* CSS Document */
body{padding:0px; margin:0px; background:url(../images/mainbg.jpg) 0 0 repeat-x #fff; color:#707070; font:14px/18px "Trebuchet MS", Arial, Helvetica, sans-serif;}
div, p, ul, h2, h3, img{padding:0px; margin:0px;}
ul{list-style-type:none;}
/*----TOP PANEL----*/
#topPan{width:747px; height:152px; position:relative; margin:0 auto; padding:0px;}
#topPan img{width:208px; height:58px; position:absolute; top:35px; left:0px;}

#topPan ul{width:480px; height:32px; position:absolute; top:76px; right:0px;}
#topPan ul li{float:left; width:79px; height:32px; padding:0 0 0 1px;}
#topPan ul li a{display:block; width:79px; height:32px; background:url(../images/menubg-normal.gif) 0 0 no-repeat #7E7B00; color:#656565; font-size:11px; font-weight:bold; line-height:32px; text-transform:uppercase; text-align:center; text-decoration:none;}
#topPan ul li a:hover{background:url(../images/menubg-hover.gif) 0 0 no-repeat #7E7B00; color:#7C7900; text-decoration:none;}
#topPan ul li a.current{background:url(../images/menubg-hover.gif) 0 0 no-repeat #7E7B00; color:#7C7900; text-decoration:none;}

#topPan ul.dropdown{width:480px; height:22px; position:absolute; top:119px; right:0px;}
#topPan ul.dropdown li{float:left; width:79px; height:22px; }
#topPan ul.dropdown li a{display:block; width:79px;background:url(../images/vertical-dot.gif) 100% 0 no-repeat #fff; color:#3E3E3E; font-size:11px; text-decoration:none; text-align:center; line-height:22px;}
#topPan ul.dropdown li a:hover{text-decoration:none; background:url(../images/vertical-dot.gif) 100% 0 no-repeat #fff; color:#7C7900;}

#topPan ul.dropdown li.verticallinenone a{display:block; width:79px;background:#fff; color:#3E3E3E; font-size:11px; text-decoration:none; text-align:center; line-height:22px;}
#topPan ul.dropdown li.verticallinenone a:hover{text-decoration:none; background:#fff; color:#7C7900;}

</style>


<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 (or "" if no corresponding tab content)]:
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


////////Stop editting////////////////

var previoustab="";

if (turntosingle==1){
document.write('<style type="text/css">\n#tabcontentcontainer{display: none;}\n</style>');
}

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";
}
if (cid!=""){
document.getElementById(cid).className="dropdown";
previoustab=cid;
}
}
}

function highlighttab(aobject){
if (typeof tabobjlinks=="undefined"){
collectddimagetabs();
}
for (i=0; i<tabobjlinks.length; i++){
tabobjlinks[i].className="";
}
aobject.className="current";
}

function collectddimagetabs(){
var tabobj=document.getElementById("tabs");
tabobjlinks=tabobj.getElementsByTagName("a");
}

function do_onload(){
collectddimagetabs();
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>
</head>

<body>
<div id="topPan">
<a href="index.php"><img src="images/logo.gif" width="208" height="58" border="0" /></a>
<div id="tabs">
<ul>
<li><a href="#" onMouseOver="expandcontent('sc1', this)">Home</a></li>
<li><a href="#" onMouseOver="expandcontent('sc2', this)">Servers</a></li>
<li><a href="#" onMouseOver="expandcontent('sc3', this)">VPS</a></li>
<li><a href="#" onMouseOver="expandcontent('sc4', this)">Hosting</a></li>
<li><a href="#" onMouseOver="expandcontent('sc5', this)">E-commerce</a></li>
<li><a href="#" onMouseOver="expandcontent('sc6', this)">Clients</a></li>
</ul>
</div>


<ul class="dropdown" id="sc1">
<li><a href="#">About Us</a></li>
<li><a href="#">Policy</a></li>
<li><a href="#">testimonial</a></li>
</ul>

<ul class="dropdown" id="sc2">
<li><a href="#">orange</a></li>
<li><a href="#">apple</a></li>
<li><a href="#">waterlemon</a></li>
</ul>

<ul class="dropdown" id="sc3">
<li><a href="#">orange</a></li>
<li><a href="#">waterlemon</a></li>
</ul>

<ul class="dropdown" id="sc4">
<li><a href="#>Web</a></li>
<li><a href="#">Email</a></li>
</ul>


<ul class="dropdown" id="sc5">
<li><a href="#">Licenses</a></li>
<li><a href="#">Web Designs</a></li>
</ul>

<ul class="dropdown" id="sc6">
<li><a href="login.php">Login</a></li>
<li><a href="register.php">Register</a></li>
</ul>




</div>
</body>
</html>


I have set

var initialtab=[1, "sc1"];


but apparently the script does not show "sc1" but i mixture of the other submenus. please help.

xiaodao
07-15-2008, 01:40 PM
if you can help, very appreciate

vwphillips
07-15-2008, 02:38 PM
there are numerous errors in your HTML/CSS

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<style type="text/css">

.halfmoon{
margin-bottom: 4px;
}

.halfmoon ul{
padding: 3px 9px 2px 5px;
margin-left: 0;
margin-top: 1px;
margin-bottom: 0;
font: bold 14px Verdana;
list-style-type: none;
text-align: left; /*set to left, center, or right to align the menu as desired*/
border-bottom: 1px solid #929492;
}

.halfmoon li{
display: inline;
margin: 0;
}

.halfmoon li a{
text-decoration: none;
padding: 3px 9px 2px 5px;
margin: 0;
margin-right: 0; /*distance between each tab*/
border-left: 1px solid #DDD;
color: black;
font: bold 14px Verdana;
background: #ECEEEC url(tabright.gif) top right no-repeat;
}

.halfmoon li a:visited{
color: black;
}

.halfmoon li a:hover, .halfmoon li a.current{
background-color: #CDDADA;
color: navy;
}

#tabcontentcontainer{
width:95%; /*width of 2nd level content*/
height:1.5em; /*height of 2nd level content. Set to largest's content height to avoid jittering.*/
}

#tabcontentcontainer UL{
display:none;
}
#tabcontentcontainer ul li{float:left; width:100px; height:32px; padding:0 0 0 1px;}

.tabcontent{
display:none;
}

</style>


<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 (or "" if no corresponding tab content)]:
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=0 //0 for no (default), 1 for yes


////////Stop editting////////////////

var previoustab=""

if (turntosingle==1)
document.write('<style type="text/css">\n#tabcontentcontainer{display: none;}\n</style>')

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"
if (cid!=""){
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 collectddimagetabs(){
var tabobj=document.getElementById("ddimagetabs")
tabobjlinks=tabobj.getElementsByTagName("A")
}

function do_onload(){
collectddimagetabs()
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></head>

<body>
<div id="ddimagetabs" class="halfmoon">
<ul>
<li><a href="http://www.dynamicdrive.com" onMouseover="expandcontent('sc1', this)">Home</a></li>
<li><a href="http://www.dynamicdrive.com/new.htm" onMouseover="expandcontent('sc2', this)">DHTML</a></li>
<li class="selected"><a href="http://www.dynamicdrive.com/style/" onMouseover="expandcontent('sc3', this)">CSS</a></li>
<li><a href="http://www.dynamicdrive.com/forums/" onMouseover="expandcontent('sc4', this)">Forums</span></a></li>
<li><a href="http://tools.dynamicdrive.com/imageoptimizer/" onMouseover="expandcontent('sc5', this)">Gif Optimizer</a></li>
</ul>
</div>

<DIV id="tabcontentcontainer">



<ul class="dropdown" id="sc1">
<li><a href="#">About Us</a></li>
<li><a href="#">Policy</a></li>
<li><a href="#">testimonial</a></li>
</ul>

<ul class="dropdown" id="sc2">
<li><a href="#">orange</a></li>
<li><a href="#">apple</a></li>
<li><a href="#">waterlemon</a></li>
</ul>

<ul class="dropdown" id="sc3">
<li><a href="#">orange</a></li>
<li><a href="#">waterlemon</a></li>
</ul>

<ul class="dropdown" id="sc4">
<li><a href="#">Web"</a></li>
<li><a href="#">Email</a></li>
</ul>


<ul class="dropdown" id="sc5">
<li><a href="#">Licenses</a></li>
<li><a href="#">Web Designs</a></li>
</ul>

<ul class="dropdown" id="sc6">
<li><a href="login.php">Login</a></li>
<li><a href="register.php">Register</a></li>
</ul>



</DIV>
</body>

</html>

xiaodao
07-15-2008, 06:11 PM
hi, i want to use my own css, do not want to use the original one, however after i change, it is not working