Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

two jscripts in one file

Status
Not open for further replies.

ifeyinwa

Programmer
Mar 26, 2003
112
US
I have two different type jscript code in my asp page .One of the scripts is a folding type menu & the other script is a drop down menu.
I had the folding type menu first, that worked fine.
however when I added the 2nd script it also worked fine but the first menu did not work .
Is there something I should declare so that the script knows that it should not just execute one jscript but the two
They are both in the head section.The scripts are below
A response will be appreciated



***The first jscript

<script language=&quot;JavaScript&quot;>
<!--
//By George Chiang ( JavaScript site.
img1=new Image()
img1.src=&quot;fold.gif&quot;
img2=new Image()
img2.src=&quot;open.gif&quot;
ns6_index=0

function change(e){

if(!document.all&&!document.getElementById)
return

if (!document.all&&document.getElementById)
ns6_index=1

var source=document.getElementById&&!document.all? e.target:event.srcElement
if (source.className==&quot;folding&quot;){
var source2=document.getElementById&&!document.all? source.parentNode.childNodes:source.parentElement.all
if (source2[2+ns6_index].style.display==&quot;none&quot;){
source2[0].src=&quot;open.gif&quot;
source2[2+ns6_index].style.display=''
}
else{
source2[0].src=&quot;fold.gif&quot;
source2[2+ns6_index].style.display=&quot;none&quot;
}
}
}
document.onclick=change
//-->
</script>




***2nd jscript
<script language=&quot;JavaScript&quot;>

//Pop-it menu- By Dynamic Drive
//For full source code and more DHTML scripts, visit //This credit MUST stay intact for use

var linkset=new Array()
//SPECIFY MENU SETS AND THEIR LINKS. FOLLOW SYNTAX LAID OUT

linkset[0]='<div class=&quot;menuitems&quot;><a href=&quot;linkset[0]+='<div class=&quot;menuitems&quot;><a href=&quot;linkset[0]+='<div class=&quot;menuitems&quot;><a href=&quot;
linkset[1]='<div class=&quot;menuitems&quot;><a href=&quot;linkset[1]+='<div class=&quot;menuitems&quot;><a href=&quot;linkset[1]+='<div class=&quot;menuitems&quot;><a href=&quot; News</a></div>'
linkset[1]+='<div class=&quot;menuitems&quot;><a href=&quot; Post</a></div>'

linkset[2]='<div class=&quot;menuitems&quot;><a href=&quot;linkset[2]+='<div class=&quot;menuitems&quot;><a href=&quot;linkset[2]+='<div class=&quot;menuitems&quot;><a href=&quot; News</a></div>'
linkset[2]+='<div class=&quot;menuitems&quot;><a href=&quot; Post</a></div>'

linkset[3]='<div class=&quot;menuitems&quot;><a href=&quot;linkset[3]+='<div class=&quot;menuitems&quot;><a href=&quot;linkset[3]+='<div class=&quot;menuitems&quot;><a href=&quot; News</a></div>'
linkset[3]+='<div class=&quot;menuitems&quot;><a href=&quot; Post</a></div>'

linkset[4]='<div class=&quot;menuitems&quot;><a href=&quot;linkset[4]+='<div class=&quot;menuitems&quot;><a href=&quot;linkset[4]+='<div class=&quot;menuitems&quot;><a href=&quot; News</a></div>'
linkset[4]+='<div class=&quot;menuitems&quot;><a href=&quot; Post</a></div>'

linkset[5]='<div class=&quot;menuitems&quot;><a href=&quot;linkset[5]+='<div class=&quot;menuitems&quot;><a href=&quot;linkset[5]+='<div class=&quot;menuitems&quot;><a href=&quot; News</a></div>'
linkset[5]+='<div class=&quot;menuitems&quot;><a href=&quot; Post</a></div>'

linkset[6]='<div class=&quot;menuitems&quot;><a href=&quot;linkset[6]+='<div class=&quot;menuitems&quot;><a href=&quot;linkset[6]+='<div class=&quot;menuitems&quot;><a href=&quot; News</a></div>'
linkset[6]+='<div class=&quot;menuitems&quot;><a href=&quot; Post</a></div>'

linkset[7]='<div class=&quot;menuitems&quot;><a href=&quot;linkset[7]+='<div class=&quot;menuitems&quot;><a href=&quot;linkset[7]+='<div class=&quot;menuitems&quot;><a href=&quot; News</a></div>'

////No need to edit beyond here

var ie4=document.all&&navigator.userAgent.indexOf(&quot;Opera&quot;)==-1
var ns6=document.getElementById&&!document.all
var ns4=document.layers

function showmenu(e,which){

if (!document.all&&!document.getElementById&&!document.layers)
return

clearhidemenu()

menuobj=ie4? document.all.popmenu : ns6? document.getElementById(&quot;popmenu&quot;) : ns4? document.popmenu : &quot;&quot;
menuobj.thestyle=(ie4||ns6)? menuobj.style : menuobj

if (ie4||ns6)
menuobj.innerHTML=which
else{
menuobj.document.write('<layer name=gui bgColor=#E6E6E6 width=165 onmouseover=&quot;clearhidemenu()&quot; onmouseout=&quot;hidemenu()&quot;>'+which+'</layer>')
menuobj.document.close()
}

menuobj.contentwidth=(ie4||ns6)? menuobj.offsetWidth : menuobj.document.gui.document.width
menuobj.contentheight=(ie4||ns6)? menuobj.offsetHeight : menuobj.document.gui.document.height
eventX=ie4? event.clientX : ns6? e.clientX : e.x
eventY=ie4? event.clientY : ns6? e.clientY : e.y

//Find out how close the mouse is to the corner of the window
var rightedge=ie4? document.body.clientWidth-eventX : window.innerWidth-eventX
var bottomedge=ie4? document.body.clientHeight-eventY : window.innerHeight-eventY

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<menuobj.contentwidth)
//move the horizontal position of the menu to the left by it's width
menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX-menuobj.contentwidth : ns6? window.pageXOffset+eventX-menuobj.contentwidth : eventX-menuobj.contentwidth
else
//position the horizontal position of the menu where the mouse was clicked
menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX : ns6? window.pageXOffset+eventX : eventX

//same concept with the vertical position
if (bottomedge<menuobj.contentheight)
menuobj.thestyle.top=ie4? document.body.scrollTop+eventY-menuobj.contentheight : ns6? window.pageYOffset+eventY-menuobj.contentheight : eventY-menuobj.contentheight
else
menuobj.thestyle.top=ie4? document.body.scrollTop+event.clientY : ns6? window.pageYOffset+eventY : eventY
menuobj.thestyle.visibility=&quot;visible&quot;
return false
}

function contains_ns6(a, b) {
//Determines if 1 element in contained in another- by Brainjar.com
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function hidemenu(){
if (window.menuobj)
menuobj.thestyle.visibility=(ie4||ns6)? &quot;hidden&quot; : &quot;hide&quot;
}

function dynamichide(e){
if (ie4&&!menuobj.contains(e.toElement))
hidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
hidemenu()
}

function delayhidemenu(){
if (ie4||ns6||ns4)
delayhide=setTimeout(&quot;hidemenu()&quot;,500)
}

function clearhidemenu(){
if (window.delayhide)
clearTimeout(delayhide)
}

function highlightmenu(e,state){
if (document.all)
source_el=event.srcElement
else if (document.getElementById)
source_el=e.target
if (source_el.className==&quot;menuitems&quot;){
source_el.id=(state==&quot;on&quot;)? &quot;mouseoverstyle&quot; : &quot;&quot;
}
else{
while(source_el.id!=&quot;popmenu&quot;){
source_el=document.getElementById? source_el.parentNode : source_el.parentElement
if (source_el.className==&quot;menuitems&quot;){
source_el.id=(state==&quot;on&quot;)? &quot;mouseoverstyle&quot; : &quot;&quot;
}
}
}
}

if (ie4||ns6)
document.onclick=hidemenu

</script>
 
make sure you dont have 2 separate onload handlers ie

window.onload = blah1()
...
window.onload = blah2()

instead write:

window.onload = blah()
fucntion blah()
{
blah1();
blah2();
}





on error goto hell
 
I do not have any onload declared in my code .
Ar you saying I shld have that then.
The script is triggered when you mouse over the words it ---2nd script
The first script is triggered when you click on the words
I do not think it is triggered when you the page is loaded.
what do yo think?
 
ok i see whats going on. Instead of having 2 onload event handlers there are 2 onclick event handlers roll them into 1

you have
document.onclick=change
in the first script and
document.onclick=hidemenu
in the second

instead just write document.onclick=HandleClick

function HandleClick()
{
change();
hidemenu();
}

this should work as long as you have your page setup correctly.
From looking at the script i can see that you need a css style called 'folding' set up and you also need an element with an id of popmenu.

Hope this helps

on error goto hell
 
my issue really is at what point or where in the script shld I put this In
 
at the bottom of each of these scripts is the onclick handler, just remove them both.

then if you want simply add another script block with the onclick handler and the function in it eg...

<script language=&quot;JavaScript&quot;>
<!--
//By George Chiang ( JavaScript site.
img1=new Image()
img1.src=&quot;fold.gif&quot;
img2=new Image()
img2.src=&quot;open.gif&quot;
ns6_index=0

function change(e){

if(!document.all&&!document.getElementById)
return

if (!document.all&&document.getElementById)
ns6_index=1

var source=document.getElementById&&!document.all? e.target:event.srcElement
if (source.className==&quot;folding&quot;){
var source2=document.getElementById&&!document.all? source.parentNode.childNodes:source.parentElement.all
if (source2[2+ns6_index].style.display==&quot;none&quot;){
source2[0].src=&quot;open.gif&quot;
source2[2+ns6_index].style.display=''
}
else{
source2[0].src=&quot;fold.gif&quot;
source2[2+ns6_index].style.display=&quot;none&quot;
}
}
}
//-->
</script>




***2nd jscript
<script language=&quot;JavaScript&quot;>

//Pop-it menu- By Dynamic Drive
//For full source code and more DHTML scripts, visit //This credit MUST stay intact for use

var linkset=new Array()
//SPECIFY MENU SETS AND THEIR LINKS. FOLLOW SYNTAX LAID OUT

linkset[0]='<div class=&quot;menuitems&quot;><a href=&quot;linkset[0]+='<div class=&quot;menuitems&quot;><a href=&quot;linkset[0]+='<div class=&quot;menuitems&quot;><a href=&quot;
linkset[1]='<div class=&quot;menuitems&quot;><a href=&quot;linkset[1]+='<div class=&quot;menuitems&quot;><a href=&quot;linkset[1]+='<div class=&quot;menuitems&quot;><a href=&quot; News</a></div>'
linkset[1]+='<div class=&quot;menuitems&quot;><a href=&quot; Post</a></div>'

linkset[2]='<div class=&quot;menuitems&quot;><a href=&quot;linkset[2]+='<div class=&quot;menuitems&quot;><a href=&quot;linkset[2]+='<div class=&quot;menuitems&quot;><a href=&quot; News</a></div>'
linkset[2]+='<div class=&quot;menuitems&quot;><a href=&quot; Post</a></div>'

linkset[3]='<div class=&quot;menuitems&quot;><a href=&quot;linkset[3]+='<div class=&quot;menuitems&quot;><a href=&quot;linkset[3]+='<div class=&quot;menuitems&quot;><a href=&quot; News</a></div>'
linkset[3]+='<div class=&quot;menuitems&quot;><a href=&quot; Post</a></div>'

linkset[4]='<div class=&quot;menuitems&quot;><a href=&quot;linkset[4]+='<div class=&quot;menuitems&quot;><a href=&quot;linkset[4]+='<div class=&quot;menuitems&quot;><a href=&quot; News</a></div>'
linkset[4]+='<div class=&quot;menuitems&quot;><a href=&quot; Post</a></div>'

linkset[5]='<div class=&quot;menuitems&quot;><a href=&quot;linkset[5]+='<div class=&quot;menuitems&quot;><a href=&quot;linkset[5]+='<div class=&quot;menuitems&quot;><a href=&quot; News</a></div>'
linkset[5]+='<div class=&quot;menuitems&quot;><a href=&quot; Post</a></div>'

linkset[6]='<div class=&quot;menuitems&quot;><a href=&quot;linkset[6]+='<div class=&quot;menuitems&quot;><a href=&quot;linkset[6]+='<div class=&quot;menuitems&quot;><a href=&quot; News</a></div>'
linkset[6]+='<div class=&quot;menuitems&quot;><a href=&quot; Post</a></div>'

linkset[7]='<div class=&quot;menuitems&quot;><a href=&quot;linkset[7]+='<div class=&quot;menuitems&quot;><a href=&quot;linkset[7]+='<div class=&quot;menuitems&quot;><a href=&quot; News</a></div>'

////No need to edit beyond here

var ie4=document.all&&navigator.userAgent.indexOf(&quot;Opera&quot;)==-1
var ns6=document.getElementById&&!document.all
var ns4=document.layers

function showmenu(e,which){

if (!document.all&&!document.getElementById&&!document.layers)
return

clearhidemenu()

menuobj=ie4? document.all.popmenu : ns6? document.getElementById(&quot;popmenu&quot;) : ns4? document.popmenu : &quot;&quot;
menuobj.thestyle=(ie4||ns6)? menuobj.style : menuobj

if (ie4||ns6)
menuobj.innerHTML=which
else{
menuobj.document.write('<layer name=gui bgColor=#E6E6E6 width=165 onmouseover=&quot;clearhidemenu()&quot; onmouseout=&quot;hidemenu()&quot;>'+which+'</layer>')
menuobj.document.close()
}

menuobj.contentwidth=(ie4||ns6)? menuobj.offsetWidth : menuobj.document.gui.document.width
menuobj.contentheight=(ie4||ns6)? menuobj.offsetHeight : menuobj.document.gui.document.height
eventX=ie4? event.clientX : ns6? e.clientX : e.x
eventY=ie4? event.clientY : ns6? e.clientY : e.y

//Find out how close the mouse is to the corner of the window
var rightedge=ie4? document.body.clientWidth-eventX : window.innerWidth-eventX
var bottomedge=ie4? document.body.clientHeight-eventY : window.innerHeight-eventY

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<menuobj.contentwidth)
//move the horizontal position of the menu to the left by it's width
menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX-menuobj.contentwidth : ns6? window.pageXOffset+eventX-menuobj.contentwidth : eventX-menuobj.contentwidth
else
//position the horizontal position of the menu where the mouse was clicked
menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX : ns6? window.pageXOffset+eventX : eventX

//same concept with the vertical position
if (bottomedge<menuobj.contentheight)
menuobj.thestyle.top=ie4? document.body.scrollTop+eventY-menuobj.contentheight : ns6? window.pageYOffset+eventY-menuobj.contentheight : eventY-menuobj.contentheight
else
menuobj.thestyle.top=ie4? document.body.scrollTop+event.clientY : ns6? window.pageYOffset+eventY : eventY
menuobj.thestyle.visibility=&quot;visible&quot;
return false
}

function contains_ns6(a, b) {
//Determines if 1 element in contained in another- by Brainjar.com
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function hidemenu(){
if (window.menuobj)
menuobj.thestyle.visibility=(ie4||ns6)? &quot;hidden&quot; : &quot;hide&quot;
}

function dynamichide(e){
if (ie4&&!menuobj.contains(e.toElement))
hidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
hidemenu()
}

function delayhidemenu(){
if (ie4||ns6||ns4)
delayhide=setTimeout(&quot;hidemenu()&quot;,500)
}

function clearhidemenu(){
if (window.delayhide)
clearTimeout(delayhide)
}

function highlightmenu(e,state){
if (document.all)
source_el=event.srcElement
else if (document.getElementById)
source_el=e.target
if (source_el.className==&quot;menuitems&quot;){
source_el.id=(state==&quot;on&quot;)? &quot;mouseoverstyle&quot; : &quot;&quot;
}
else{
while(source_el.id!=&quot;popmenu&quot;){
source_el=document.getElementById? source_el.parentNode : source_el.parentElement
if (source_el.className==&quot;menuitems&quot;){
source_el.id=(state==&quot;on&quot;)? &quot;mouseoverstyle&quot; : &quot;&quot;
}
}
}
}
</script>

//**ADDED SCRIPT**\<script language=javascript>
document.onclick=HandleEvent
function HandleEvent()
{
change()
hidemenu()
}
</script>

place this entire script immediately after the body tag


on error goto hell
 
thank you thank you so much much much it worked !!!
I am going to have me a good holiday week/end thanks to you
I sincerly do appreciate this.
Regards
ify
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top