View Full Version : 2 Javascripts together=not working
Nikkon
03-20-2003, 01:39 PM
Ok...here is my problem...(BTW I looked at the FAQ for this, and it didn't seem to fit my scenario)...I have the static menu and the vertical scrolling text box at the same time. I have the menu on, but as soon as I add the text box the menu doesnt work. The text box does though.
Help would be greatly appreciated..thanks:thumbsup:
Roy Sinclair
03-20-2003, 03:24 PM
Rather than type all this advice over again, look here (http://www.codingforums.com/showthread.php?s=&threadid=2090).
We're willing to help but so far you've given nothing except a notice that you've got a problem.
Nikkon
03-20-2003, 09:58 PM
I already looked at that....I searched and didnt find anything that helped me enough.
I dont know what else to say about my problem...so yea....way to rock on the n00b
I have the static menu
What is "the static menu"? Is it a script on Dynamic Drive? Where's the code?
and the vertical scrolling text box
What is "the vertical scrolling text box"? Is it a script on Dynamic Drive? Where's the code?
as I add the text box the menu doesnt work
Define "doesn't work"
Doesn't appear?
Doesn't drop down?
Has the wrong text?
Has no text?
Appears in the wrong place?
Causes a javascript error?
- object expected?
- function not defined?
- anyone of a hundred javascript errors?
As you can see there are many questions (even more than I have posted).
What Mr Sinclair was pointing out is that you have not supplied even the minimal amout of information that would help solve your problem.
Peering into my crystal ball - here is my answer
"Ommmmmm - there are 2 onload handlers - one is overriding the other - Ommm - look here (http://javascriptkit.com/javatutors/multiplejava.shtml) "
(sorry about the sarcasm but this question comes up a lot).
If my crystall ball didn't answer the question then please feel free to post a more detailed explanation.
The ideal is to post a url to the page you are having problems with. This will get your problem solved a lot sooner.
Roy Sinclair
03-20-2003, 10:40 PM
Maybe the advise isn't worded so you could understand it so I guess I'll try again. We can't help you with your problem so far because you haven't shown us the problem. It takes a link to the broken page or posting the script(s) and the html (only if it's rather short, there's a size limit on posts after all) so we can see the problem. So far all you've given us is the fact that you have a problem with two scripts where one of them causes the other one to not work.
I'm really sorry you couldn't find anything when you searched either since this is one of the most common type of problem asked on this board (two scripts not working together) and at least one other person asked a similar question just today.
Don't give up! Maybe the hint that'll get you going again will be found in one of the following threads:
http://www.codingforums.com/showthread.php?s=&threadid=16662&highlight=scripts
http://www.codingforums.com/showthread.php?s=&threadid=16537&highlight=scripts
http://www.codingforums.com/showthread.php?s=&threadid=15758&highlight=scripts
http://www.codingforums.com/showthread.php?s=&threadid=15805&highlight=scripts
A tutorial on this kind of problem may also be a great help:
http://www.javascriptkit.com/javatutors/multiplejava2.shtml
Nikkon
03-20-2003, 11:04 PM
The static menu was found at:Static Menu (http://javascriptkit.com/script/script2/staticmenu.shtml)
The scrolling text box was found here: Vertical Text box (http://javascriptkit.com/script/script2/verticalscroller.shtml)
This is what my body tag looks like: <BODY OnLoad="setVariables();checkLocation()" text="yellow" link="silver" vlink="silver" alink="silver" background="camouflage2.gif">
If you need anything else please be really specific....This is my second day using anything Javascript related
shevegen
03-20-2003, 11:12 PM
I am a noob too but while reading your post i had the impression that it might help if you provide the whole example of your javascript - will make it easier for people to lookup and check.
Nikkon
03-20-2003, 11:15 PM
alright here it is....well at least the two things:
<BODY OnLoad="setVariables();checkLocation()" text="yellow" link="silver" vlink="silver" alink="silver" background="camouflage2.gif">
<SCRIPT LANGUAGE="JavaScript">
/*
Created by Randy Bennet http://home.thezone.net/~rbennett/utility/javahead.htm
Featured on JavaScript Kit (http://javascriptkit.com)
For this and over 400+ free scripts, visit http://javascriptkit.com
*/
function setVariables() {
if (document.layers) {
v=".top=";
dS="document.";
sD="";
y="window.pageYOffset";
}
else if (document.all){
v=".pixelTop=";
dS="";
sD=".style";
y="document.body.scrollTop";
}
else if (document.getElementById){
y="window.pageYOffset";
}
}
function checkLocation() {
object="object1";
yy=eval(y);
if (document.getElementById)
document.getElementById("object1").style.top=yy
else
eval(dS+object+sD+v+yy)
setTimeout("checkLocation()",10);
}
</script>
<div id="object1" style="position:absolute; visibility:show; left:0px; top:0px; z-index:5">
<table width=150 border=0 cellspacing=20 cellpadding=0 >
<tr>
<td background="camouflage2.gif"><CENTER><b>Squad Domination</b></CENTER></td>
</tr>
<tr>
<td background="camouflage2.gif"><a href="home.html" >Home</a></td>
</tr>
<tr>
<td background="camouflage2.gif"><a href="members.html" >Members</a></td>
</tr>
<tr>
<td background="camouflage2.gif"><a href="scheldue.html" >Scheldue</a></td>
</tr>
<tr>
<td background="camouflage2.gif"><a href="recruitment.html" >Recruitment</a></td>
</tr>
<tr>
<td background="camouflage2.gif"><a href="rules.html" >Rules and Challenges</a></td>
</tr>
<tr>
<td background="camouflage2.gif"><a href="http://amazingforums.com/forum1/SQUADD/forum.html" >Forum</a></td>
</tr>
</table>
</div>
^now i have some other stuff and heres where it continues^
<script language="javascript">
//Vertical Scroller v1.2- by Brian of www.ScriptAsylum.com
//Updated for bug fixes
//Visit JavaScript Kit (http://javascriptkit.com) for script
//ENTER CONTENT TO SCROLL BELOW.
var content='<p>03.18.03-The new site is coming.This is the first day of production.It seems to be much better then the first.My mic is still broke.</p>';
var boxheight=300; // BACKGROUND BOX HEIGHT IN PIXELS.
var boxwidth=300; // BACKGROUND BOX WIDTH IN PIXELS.
var boxcolor="black"; // BACKGROUND BOX COLOR.
var speed=50; // SPEED OF SCROLL IN MILLISECONDS (1 SECOND=1000 MILLISECONDS)..
var pixelstep=2; // PIXELS "STEPS" PER REPITITION.
var godown=false; // TOP TO BOTTOM=TRUE , BOTTOM TO TOP=FALSE
// DO NOT EDIT BEYOND THIS POINT
var outer,inner,elementheight,ref,refX,refY;
var w3c=(document.getElementById)?true:false;
var ns4=(document.layers)?true:false;
var ie4=(document.all && !w3c)?true:false;
var ie5=(document.all && w3c)?true:false;
var ns6=(w3c && navigator.appName.indexOf("Netscape")>=0)?true:false;
var txt='';
if(ns4){
txt+='<table cellpadding=0 cellspacing=0 border=0 height='+boxheight+' width='+boxwidth+'><tr><td>';
txt+='<ilayer name="ref" bgcolor="'+boxcolor+'" width='+boxwidth+' height='+boxheight+'></ilayer>';
txt+='</td></tr></table>'
txt+='<layer name="outer" bgcolor="'+boxcolor+'" visibility="hidden" width='+boxwidth+' height='+boxheight+'>';
txt+='<layer name="inner" width='+(boxwidth-4)+' height='+(boxheight-4)+' visibility="hidden" left="2" top="2" >'+content+'</layer>';
txt+='</layer>';
}else{
txt+='<div id="ref" style="position:relative; width:'+boxwidth+'; height:'+boxheight+'; background-color:'+boxcolor+';" ></div>';
txt+='<div id="outer" style="position:absolute; width:'+boxwidth+'; height:'+boxheight+'; visibility:hidden; background-color:'+boxcolor+'; overflow:hidden" >';
txt+='<div id="inner" style="position:absolute; visibility:visible; left:2px; top:2px; width:'+(boxwidth-4)+'; overflow:hidden; cursor:default;">'+content+'</div>';
txt+='</div>';
}
document.write(txt);
function getElHeight(el){
if(ns4)return (el.document.height)? el.document.height : el.clip.bottom-el.clip.top;
else if(ie4||ie5)return (el.style.height)? el.style.height : el.clientHeight;
else return (el.style.height)? parseInt(el.style.height):parseInt(el.offsetHeight);
}
function getPageLeft(el){
var x;
if(ns4)return el.pageX;
if(ie4||w3c){
x = 0;
while(el.offsetParent!=null){
x+=el.offsetLeft;
el=el.offsetParent;
}
x+=el.offsetLeft;
return x;
}}
function getPageTop(el){
var y;
if(ns4)return el.pageY;
if(ie4||w3c){
y=0;
while(el.offsetParent!=null){
y+=el.offsetTop;
el=el.offsetParent;
}
y+=el.offsetTop;
return y;
}}
function scrollbox(){
if(ns4){
inner.top+=(godown)? pixelstep: -pixelstep;
if(godown){
if(inner.top>boxheight)inner.top=-elementheight;
}else{
if(inner.top<2-elementheight)inner.top=boxheight+2;
}}else{
inner.style.top=parseInt(inner.style.top)+((godown)? pixelstep: -pixelstep)+'px';
if(godown){
if(parseInt(inner.style.top)>boxheight)inner.style.top=-elementheight+'px';
}else{
if(parseInt(inner.style.top)<2-elementheight)inner.style.top=boxheight+2+'px';
}}}
window.onresize=function(){
if(ns4)setTimeout('history.go(0)', 400);
else{
outer.style.left=getPageLeft(ref)+'px';
outer.style.top=getPageTop(ref)+'px';
}}
window.onload=function(){
outer=(ns4)?document.layers['outer']:(ie4)?document.all['outer']:document.getElementById('outer');
inner=(ns4)?outer.document.layers['inner']:(ie4)?document.all['inner']:document.getElementById('inner');
ref=(ns4)?document.layers['ref']:(ie4)?document.all['ref']:document.getElementById('ref');
elementheight=getElHeight(inner);
if(ns4){
outer.moveTo(getPageLeft(ref),getPageTop(ref));
outer.clip.width=boxwidth;
outer.clip.height=boxheight;
inner.top=(godown)? -elementheight : boxheight-2;
inner.clip.width=boxwidth-4;
inner.clip.height=elementheight;
outer.visibility="show";
inner.visibility="show";
}else{
outer.style.left=getPageLeft(ref)+'px';
outer.style.top=getPageTop(ref)+'px';
inner.style.top=((godown)? -elementheight : boxheight)+'px';
inner.style.clip='rect(0px, '+(boxwidth-4)+'px, '+(elementheight)+'px, 0px)';
outer.style.visibility="visible";
}
setInterval('scrollbox()',speed);
}
</script>
......thanks a lot........
Nikkon
03-20-2003, 11:22 PM
alright here it is....well at least the two things:
<BODY OnLoad="setVariables();checkLocation()" text="yellow" link="silver" vlink="silver" alink="silver" background="camouflage2.gif">
<SCRIPT LANGUAGE="JavaScript">
/*
Created by Randy Bennet http://home.thezone.net/~rbennett/utility/javahead.htm
Featured on JavaScript Kit (http://javascriptkit.com)
For this and over 400+ free scripts, visit http://javascriptkit.com
*/
function setVariables() {
if (document.layers) {
v=".top=";
dS="document.";
sD="";
y="window.pageYOffset";
}
else if (document.all){
v=".pixelTop=";
dS="";
sD=".style";
y="document.body.scrollTop";
}
else if (document.getElementById){
y="window.pageYOffset";
}
}
function checkLocation() {
object="object1";
yy=eval(y);
if (document.getElementById)
document.getElementById("object1").style.top=yy
else
eval(dS+object+sD+v+yy)
setTimeout("checkLocation()",10);
}
</script>
<div id="object1" style="position:absolute; visibility:show; left:0px; top:0px; z-index:5">
<table width=150 border=0 cellspacing=20 cellpadding=0 >
<tr>
<td background="camouflage2.gif"><CENTER><b>Squad Domination</b></CENTER></td>
</tr>
<tr>
<td background="camouflage2.gif"><a href="home.html" >Home</a></td>
</tr>
<tr>
<td background="camouflage2.gif"><a href="members.html" >Members</a></td>
</tr>
<tr>
<td background="camouflage2.gif"><a href="scheldue.html" >Scheldue</a></td>
</tr>
<tr>
<td background="camouflage2.gif"><a href="recruitment.html" >Recruitment</a></td>
</tr>
<tr>
<td background="camouflage2.gif"><a href="rules.html" >Rules and Challenges</a></td>
</tr>
<tr>
<td background="camouflage2.gif"><a href="http://amazingforums.com/forum1/SQUADD/forum.html" >Forum</a></td>
</tr>
</table>
</div>
^now i have some other stuff and heres where it continues^
<script language="javascript">
//Vertical Scroller v1.2- by Brian of www.ScriptAsylum.com
//Updated for bug fixes
//Visit JavaScript Kit (http://javascriptkit.com) for script
//ENTER CONTENT TO SCROLL BELOW.
var content='<p>03.18.03-The new site is coming.This is the first day of production.It seems to be much better then the first.My mic is still broke.</p>';
var boxheight=300; // BACKGROUND BOX HEIGHT IN PIXELS.
var boxwidth=300; // BACKGROUND BOX WIDTH IN PIXELS.
var boxcolor="black"; // BACKGROUND BOX COLOR.
var speed=50; // SPEED OF SCROLL IN MILLISECONDS (1 SECOND=1000 MILLISECONDS)..
var pixelstep=2; // PIXELS "STEPS" PER REPITITION.
var godown=false; // TOP TO BOTTOM=TRUE , BOTTOM TO TOP=FALSE
// DO NOT EDIT BEYOND THIS POINT
var outer,inner,elementheight,ref,refX,refY;
var w3c=(document.getElementById)?true:false;
var ns4=(document.layers)?true:false;
var ie4=(document.all && !w3c)?true:false;
var ie5=(document.all && w3c)?true:false;
var ns6=(w3c && navigator.appName.indexOf("Netscape")>=0)?true:false;
var txt='';
if(ns4){
txt+='<table cellpadding=0 cellspacing=0 border=0 height='+boxheight+' width='+boxwidth+'><tr><td>';
txt+='<ilayer name="ref" bgcolor="'+boxcolor+'" width='+boxwidth+' height='+boxheight+'></ilayer>';
txt+='</td></tr></table>'
txt+='<layer name="outer" bgcolor="'+boxcolor+'" visibility="hidden" width='+boxwidth+' height='+boxheight+'>';
txt+='<layer name="inner" width='+(boxwidth-4)+' height='+(boxheight-4)+' visibility="hidden" left="2" top="2" >'+content+'</layer>';
txt+='</layer>';
}else{
txt+='<div id="ref" style="position:relative; width:'+boxwidth+'; height:'+boxheight+'; background-color:'+boxcolor+';" ></div>';
txt+='<div id="outer" style="position:absolute; width:'+boxwidth+'; height:'+boxheight+'; visibility:hidden; background-color:'+boxcolor+'; overflow:hidden" >';
txt+='<div id="inner" style="position:absolute; visibility:visible; left:2px; top:2px; width:'+(boxwidth-4)+'; overflow:hidden; cursor:default;">'+content+'</div>';
txt+='</div>';
}
document.write(txt);
function getElHeight(el){
if(ns4)return (el.document.height)? el.document.height : el.clip.bottom-el.clip.top;
else if(ie4||ie5)return (el.style.height)? el.style.height : el.clientHeight;
else return (el.style.height)? parseInt(el.style.height):parseInt(el.offsetHeight);
}
function getPageLeft(el){
var x;
if(ns4)return el.pageX;
if(ie4||w3c){
x = 0;
while(el.offsetParent!=null){
x+=el.offsetLeft;
el=el.offsetParent;
}
x+=el.offsetLeft;
return x;
}}
function getPageTop(el){
var y;
if(ns4)return el.pageY;
if(ie4||w3c){
y=0;
while(el.offsetParent!=null){
y+=el.offsetTop;
el=el.offsetParent;
}
y+=el.offsetTop;
return y;
}}
function scrollbox(){
if(ns4){
inner.top+=(godown)? pixelstep: -pixelstep;
if(godown){
if(inner.top>boxheight)inner.top=-elementheight;
}else{
if(inner.top<2-elementheight)inner.top=boxheight+2;
}}else{
inner.style.top=parseInt(inner.style.top)+((godown)? pixelstep: -pixelstep)+'px';
if(godown){
if(parseInt(inner.style.top)>boxheight)inner.style.top=-elementheight+'px';
}else{
if(parseInt(inner.style.top)<2-elementheight)inner.style.top=boxheight+2+'px';
}}}
window.onresize=function(){
if(ns4)setTimeout('history.go(0)', 400);
else{
outer.style.left=getPageLeft(ref)+'px';
outer.style.top=getPageTop(ref)+'px';
}}
window.onload=function(){
outer=(ns4)?document.layers['outer']:(ie4)?document.all['outer']:document.getElementById('outer');
inner=(ns4)?outer.document.layers['inner']:(ie4)?document.all['inner']:document.getElementById('inner');
ref=(ns4)?document.layers['ref']:(ie4)?document.all['ref']:document.getElementById('ref');
elementheight=getElHeight(inner);
if(ns4){
outer.moveTo(getPageLeft(ref),getPageTop(ref));
outer.clip.width=boxwidth;
outer.clip.height=boxheight;
inner.top=(godown)? -elementheight : boxheight-2;
inner.clip.width=boxwidth-4;
inner.clip.height=elementheight;
outer.visibility="show";
inner.visibility="show";
}else{
outer.style.left=getPageLeft(ref)+'px';
outer.style.top=getPageTop(ref)+'px';
inner.style.top=((godown)? -elementheight : boxheight)+'px';
inner.style.clip='rect(0px, '+(boxwidth-4)+'px, '+(elementheight)+'px, 0px)';
outer.style.visibility="visible";
}
setInterval('scrollbox()',speed);
}
</script>
......thanks a lot........
Ok, try this
in the second script change
window.onload=function(){
to
function startScroller(){
and change
<BODY OnLoad="setVariables();checkLocation()" text="yellow" link="silver" vlink="silver" alink="silver" background="camouflage2.gif">
to
<BODY onload="setVariables();checkLocation();startScroller();" text="yellow" link="silver" vlink="silver" alink="silver" background="camouflage2.gif">
Nikkon
03-21-2003, 03:19 AM
wow...you guys are amazing....THANKS A LOT! :D
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.