Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Navigation bar throwing error

    Hey everyone, I am new to Javascript and I am creating a navigation bar, and I was just wondering why this code is throwing an erorr. It is saying I am missing a "," but whenever i do it nothing happens...here is the code:

    There error is on Line 5 and this is what it says:

    Description File Line Column

    Expected ',' ddtabmenu.js 1 1


    Code:
    
    
    var ddtabmenu={
    	disabletablinks: false,
    	snap2original: [true, 300],
    
    	currentpageurl: window.location.href.replace("http://"+window.location.hostname, "").replace(/^\//, ""), 
    definemenu:function(tabid, dselected){
    	this[tabid+"-menuitems"]=null
    	this[tabid+"-dselected"]=-1
    	this.addEvent(window, function(){ddtabmenu.init(tabid, dselected)}, "load")
    },
    
    showsubmenu:function(tabid, targetitem){
    	var menuitems=this[tabid+"-menuitems"]
    	this.clearrevert2default(tabid)
     for (i=0; i<menuitems.length; i++){
    		menuitems[i].className=""
    		if (typeof menuitems[i].hasSubContent!="undefined")
    			document.getElementById(menuitems[i].getAttribute("rel")).style.display="none"
    	}
    	targetitem.className="current"
    	if (typeof targetitem.hasSubContent!="undefined")
    		document.getElementById(targetitem.getAttribute("rel")).style.display="block"
    },
    
    isSelected:function(menuurl){
    	var menuurl=menuurl.replace("http://"+menuurl.hostname, "").replace(/^\//, "")
    	return (ddtabmenu.currentpageurl==menuurl)
    },
    
    isContained:function(m, e){
    	var e=window.event || e
    	var c=e.relatedTarget || ((e.type=="mouseover")? e.fromElement : e.toElement)
    	while (c && c!=m)try {c=c.parentNode} catch(e){c=m}
    	if (c==m)
    		return true
    	else
    		return false
    },
    
    revert2default:function(outobj, tabid, e){
    	if (!ddtabmenu.isContained(outobj, tabid, e)){
    		window["hidetimer_"+tabid]=setTimeout(function(){
    			ddtabmenu.showsubmenu(tabid, ddtabmenu[tabid+"-dselected"])
    		}, ddtabmenu.snap2original[1])
    	}
    },
    
    clearrevert2default:function(tabid){
     if (typeof window["hidetimer_"+tabid]!="undefined")
    		clearTimeout(window["hidetimer_"+tabid])
    },
    
    addEvent:function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
    	var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
    	if (target.addEventListener)
    		target.addEventListener(tasktype, functionref, false)
    	else if (target.attachEvent)
    		target.attachEvent(tasktype, functionref)
    },
    
    init:function(tabid, dselected){
    	var menuitems=document.getElementById(tabid).getElementsByTagName("a")
    	this[tabid+"-menuitems"]=menuitems
    	for (var x=0; x<menuitems.length; x++){
    		if (menuitems[x].getAttribute("rel")){
    			this[tabid+"-menuitems"][x].hasSubContent=true
    			if (ddtabmenu.disabletablinks)
    				menuitems[x].onclick=function(){return false}
    			if (ddtabmenu.snap2original[0]==true){
    				var submenu=document.getElementById(menuitems[x].getAttribute("rel"))
    				menuitems[x].onmouseout=function(e){ddtabmenu.revert2default(submenu, tabid, e)}
    				submenu.onmouseover=function(){ddtabmenu.clearrevert2default(tabid)}
    				submenu.onmouseout=function(e){ddtabmenu.revert2default(this, tabid, e)}
    			}
    		}
    		else //for items without a submenu, add onMouseout effect
    			menuitems[x].onmouseout=function(e){this.className=""; if (ddtabmenu.snap2original[0]==true) ddtabmenu.revert2default(this, tabid, e)}
    		menuitems[x].onmouseover=function(){ddtabmenu.showsubmenu(tabid, this)}
    		if (dselected=="auto" && typeof setalready=="undefined" && this.isSelected(menuitems[x].href)){
    			ddtabmenu.showsubmenu(tabid, menuitems[x])
    			this[tabid+"-dselected"]=menuitems[x]
    			var setalready=true
    		}
    		else if (parseInt(dselected)==x){
    			ddtabmenu.showsubmenu(tabid, menuitems[x])
    			this[tabid+"-dselected"]=menuitems[x]
    		}
    	}
    }
    }
    Thanks for all the help

  • #2
    Regular Coder
    Join Date
    Mar 2008
    Location
    London
    Posts
    152
    Thanks
    4
    Thanked 42 Times in 42 Posts
    Have you followed correct steps as mentioned in the Dynamic Drive website from where you picked this script ? http://www.dynamicdrive.com/dynamici...ddtabdemos.htm

    I compared your script with the original one, and its same. There might be some other issue related to what you have coded in your other HTML/JS files.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •