3 Replies - 2088 Views - Last Post: 27 September 2008 - 01:45 AM

#1 edu2004eu  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 81
  • Joined: 27-August 07

Modify an existing script

Posted 19 September 2008 - 12:39 PM

Hi. I have a JS code that does a flyout menu. My problem is that it only works for a menu which is on the left side and expands on the right. But I want it to work the other way too.

The menu can be found here: http://www.javascrip...ticalmenu.shtml.

I know that if I change the this.getElementsByTagName("ul")[0].style.left=this.parentNode.offsetWidth+submenuoffset+"px" code into this.getElementsByTagName("ul")[0].style.right=this.parentNode.offsetWidth+submenuoffset+"px" and something in the CSS file, it works. My problem is, how do I make an IF statement which checks which menu it is? Note: the var menuids=new Array("verticalmenu") code can have more menus, which is in my case. I want the code to be this.getElementsByTagName("ul")[0].style.left=this.parentNode.offsetWidth+submenuoffset+"px" when the 'verticalmenu' is displayed and the this.getElementsByTagName("ul")[0].style.right=this.parentNode.offsetWidth+submenuoffset+"px" code when the 'verticalmenu2' is displayed.

O hope it's clear enough.

Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: Modify an existing script

#2 mocker  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 50
  • View blog
  • Posts: 466
  • Joined: 14-October 07

Re: Modify an existing script

Posted 19 September 2008 - 01:54 PM

I copied the javascript from the link you mentioned

original
function createcssmenu(){
for (var i=0; i<menuids.length; i++){
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
	for (var t=0; t<ultags.length; t++){
	var spanref=document.createElement("span")
		spanref.className="arrowdiv"
		spanref.innerHTML="&nbsp;&nbsp;"
		ultags[t].parentNode.getElementsByTagName("a")[0].appendChild(spanref)
	ultags[t].parentNode.onmouseover=function(){
	this.getElementsByTagName("ul")[0].style.left=this.parentNode.offsetWidth+submenuoffset+"px"
	this.getElementsByTagName("ul")[0].style.display="block"
	}
	ultags[t].parentNode.onmouseout=function(){
	this.getElementsByTagName("ul")[0].style.display="none"
	}
	}
  }
}





Change to
function createcssmenu(){
for (var i=0; i<menuids.length; i++){
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
	for (var t=0; t<ultags.length; t++){
	var spanref=document.createElement("span")
		spanref.className="arrowdiv"
		spanref.innerHTML="&nbsp;&nbsp;"
		ultags[t].parentNode.getElementsByTagName("a")[0].appendChild(spanref)
	ultags[t].parentNode.onmouseover=function(){
	if(this.id=="verticalmenu"){
	this.getElementsByTagName("ul")[0].style.left=this.parentNode.offsetWidth+submenuoffset+"px" 
	}
	else {
	this.getElementsByTagName("ul")[0].style.right=this.parentNode.offsetWidth+submenuoffset+"px"
	}
	this.getElementsByTagName("ul")[0].style.display="block"
	}
	ultags[t].parentNode.onmouseout=function(){
	this.getElementsByTagName("ul")[0].style.display="none"
	}
	}
  }
}


This post has been edited by mocker: 19 September 2008 - 01:55 PM

Was This Post Helpful? 1
  • +
  • -

#3 edu2004eu  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 81
  • Joined: 27-August 07

Re: Modify an existing script

Posted 19 September 2008 - 01:58 PM

That doesn't work either. Idk why... I have tried something else... something like if(menuids[i]=="verticalmenu") ... else ... but that didn't work either... isn't there a method to output this.id or menuids[i]?

EDIT: the code was OK, both mine and yours, the CSS wasn't :P Thank you very much.

This post has been edited by edu2004eu: 19 September 2008 - 02:28 PM

Was This Post Helpful? 0
  • +
  • -

#4 bojourn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 27-September 08

Re: Modify an existing script

Posted 27 September 2008 - 01:45 AM

dear frens.... i need some advice on how to put an image within the alert box.... 2nd alert box i must say....
thank you.

<script language="Javascript">
<!-----hide from old browsers
alert('HIGHLY RESTRICTED AREA!');
//--------->
</SCRIPT>


<script LANGUAGE="Javascript">
<!-- Begin
var agree = confirm("VIOLATION OF THIS SYSTEM WILL RESULT TO THE LAW OF XXXXXXX. ANY UNAUTHORIZED ACCESS IS PROHIBITED");
if (agree)
document.write("");
else
history.go(-1);
// End -->
</SCRIPT>
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1