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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Location
    Mechanicsburg, PA
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with two javascript codes on same page

    Hi,
    I have been trying to figure this out for a few hours now and searched on the internet and can't figure out what is wrong. I actually have 3 javascripts on this page I am starting but I took off the one because it's not the problem and I don't want to confuse anyone here. These two are the problem: When I take off the scroll ticker the background colors change (javascript) but when I add the ticker back on in a table the background colors won't change.

    Here is the html code for the page if anyone can help me I'd appreciate it. The person would like to have both these working on the same page. Thank you.

    <html>

    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>I Just Wanna Race</title>
    <script language="JavaScript">
    <!--
    //you can assign the initial color of the background here
    r=255;
    g=255;
    b=255;
    flag=0;
    t=new Array;
    o=new Array;
    d=new Array;

    function hex(a,c)
    {
    t[a]=Math.floor(c/16)
    o[a]=c%16
    switch (t[a])
    {
    case 10:
    t[a]='A';
    break;
    case 11:
    t[a]='B';
    break;
    case 12:
    t[a]='C';
    break;
    case 13:
    t[a]='D';
    break;
    case 14:
    t[a]='E';
    break;
    case 15:
    t[a]='F';
    break;
    default:
    break;
    }
    switch (o[a])
    {
    case 10:
    o[a]='A';
    break;
    case 11:
    o[a]='B';
    break;
    case 12:
    o[a]='C';
    break;
    case 13:
    o[a]='D';
    break;
    case 14:
    o[a]='E';
    break;
    case 15:
    o[a]='F';
    break;
    default:
    break;
    }
    }

    function ran(a,c)
    {
    if ((Math.random()>2/3||c==0)&&c<255)
    {
    c++
    d[a]=2;
    }
    else
    {
    if ((Math.random()<=1/2||c==255)&&c>0)
    {
    c--
    d[a]=1;
    }
    else d[a]=0;
    }
    return c
    }
    function do_it(a,c)
    {
    if ((d[a]==2&&c<255)||c==0)
    {
    c++
    d[a]=2
    }
    else
    if ((d[a]==1&&c>0)||c==255)
    {
    c--;
    d[a]=1;
    }
    if (a==3)
    {
    if (d[1]==0&&d[2]==0&&d[3]==0)
    flag=1
    }
    return c
    }
    function bgtrans()
    {
    if (flag==0)
    {
    r=ran(1, r);
    g=ran(2, g);
    b=ran(3, b);
    hex(1,r)
    hex(2,g)
    hex(3,b)
    document.bgColor="#"+t[1]+o[1]+t[2]+o[2]+t[3]+o[3]
    flag=50
    }
    else
    {
    r=do_it(1, r)
    g=do_it(2,g)
    b=do_it(3,b)
    hex(1,r)
    hex(2,g)
    hex(3,b)
    document.bgColor="#"+t[1]+o[1]+t[2]+o[2]+t[3]+o[3]
    flag--
    }
    if (document.all)
    setTimeout('bgtrans()',50)
    }
    //-->
    </script>
    </head>

    <body>
    <!-- --><body onload="bgtrans()"><!-- -->
    <p align="center">&nbsp;</p>
    <div align="center">
    <table border="1" width="95%">
    <tr>
    <td bgcolor="#FFFFFF" align="center" width="183"><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><strong><font color="#C00000">RACING SCHEDULE</font></p><p><font color="#0000FF">Thurs. May 11:</font><br><font color=#C00000">Susquehanna Speedway Park</font><br><small>Sprints, Xtreme Stocks & W.O.W.</small><br><br><p><font color="#0000FF">Fri. May 12:</font><br><font color=#C00000">Susquehanna Speedway Park</font><br><small>Women on Wheels Mini Vans,<br>Trail Motors Super Sportsman,<br>Street Stocks & Legends Cars</small><br><br><font color="#C00000">Williams Grove Speedway</font><br><small>Sprints & ARDC Midgets</small><br><br><font color="#0000FF">Sat. May 13</font><br><font color="#C00000">Lincoln Speedway</font><br><small>410 Sprints, 358 Sprints & Thundercars</small><br><br><font color="#C00000">Port Royal Speedway</font><br><small>Sprints, Late Models,<br>Pro Stocks & Enduro Cars</small><br><br><font color="#C00000">Williams Grove Speedway</font><br><small>Super Sportsman,<br>Late Models & Street Stocks</small>';

    var boxheight=150; // BACKGROUND BOX HEIGHT IN PIXELS.
    var boxwidth=250; // BACKGROUND BOX WIDTH IN PIXELS.
    var boxcolor="#FFFFFF"; // 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>

    </td>
    <td bgcolor="#FFFFFF" align="center">&nbsp;</td>
    <td bgcolor="#FFFFFF" align="center">&nbsp;</td>
    </tr>
    </table>
    </div>
    </body>

    </html>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    If you had used the search feature you would have discovered that this question has been asked and answered a zillion times.

    The problem is that you have two body or window onload events - and the second overwrites the first.

    For a detailed tutorial see:-

    http://www.javascriptkit.com/javatut...iplejava.shtml

  • #3
    New to the CF scene
    Join Date
    May 2006
    Location
    Mechanicsburg, PA
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I did look at that SAME page a ZILLION times and I did search on here and on the internet for hours and I tried to figure it out and couldn't! If I could have figured it out I wouldn't have posted. I know I have two scripts that aren't working together and that they have the same body/window onload events but I can't get it right.

    Thanks for nothing!

  • #4
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,505
    Thanks
    3
    Thanked 501 Times in 488 Posts
    well it would not work for me to start with but works now
    dont know what I did
    Code:
    <html>
    
    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>I Just Wanna Race</title>
    <script language="JavaScript">
    <!--
    //you can assign the initial color of the background here
    r=255;
    g=255;
    b=255;
    flag=0;
    t=new Array;
    o=new Array;
    d=new Array;
    
    function hex(a,c)
    {
    t[a]=Math.floor(c/16)
    o[a]=c%16
    switch (t[a])
    {
    case 10:
    t[a]='A';
    break;
    case 11:
    t[a]='B';
    break;
    case 12:
    t[a]='C';
    break;
    case 13:
    t[a]='D';
    break;
    case 14:
    t[a]='E';
    break;
    case 15:
    t[a]='F';
    break;
    default:
    break;
    }
    switch (o[a])
    {
    case 10:
    o[a]='A';
    break;
    case 11:
    o[a]='B';
    break;
    case 12:
    o[a]='C';
    break;
    case 13:
    o[a]='D';
    break;
    case 14:
    o[a]='E';
    break;
    case 15:
    o[a]='F';
    break;
    default:
    break;
    }
    }
    
    function ran(a,c){
     if ((Math.random()>2/3||c==0)&&c<255){
      c++
      d[a]=2;
      }
      else {
      if ((Math.random()<=1/2||c==255)&&c>0){
      c--
      d[a]=1;
      }
      else d[a]=0;
     }
     return c
    }
    
    function do_it(a,c){
     if ((d[a]==2&&c<255)||c==0){
      c++
      d[a]=2
     }
     else
     if ((d[a]==1&&c>0)||c==255){
      c--;
      d[a]=1;
     }
     if (a==3){
      if (d[1]==0&&d[2]==0&&d[3]==0)
      flag=1
     }
     return c
    }
    
    function bgtrans(){
     if (flag==0){
      r=ran(1, r);
      g=ran(2, g);
      b=ran(3, b);
      hex(1,r)
      hex(2,g)
      hex(3,b)
      document.bgColor="#"+t[1]+o[1]+t[2]+o[2]+t[3]+o[3]
      flag=50
     }
     else {
      r=do_it(1, r)
      g=do_it(2,g)
      b=do_it(3,b)
      hex(1,r)
      hex(2,g)
      hex(3,b)
      document.bgColor="#"+t[1]+o[1]+t[2]+o[2]+t[3]+o[3]
      flag--
     }
     if (document.all)
     setTimeout('bgtrans()',50)
    }
    
    //-->
    </script>
    </head>
    
    <body>
    <p align="center">&nbsp;</p>
    <div align="center">
    <table border="1" width="95%">
    <tr>
    <td bgcolor="#FFFFFF" align="center" width="183"><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><strong><font color="#C00000">RACING SCHEDULE</font></p><p><font color="#0000FF">Thurs. May 11:</font><br><font color=#C00000">Susquehanna Speedway Park</font><br><small>Sprints, Xtreme Stocks & W.O.W.</small><br><br><p><font color="#0000FF">Fri. May 12:</font><br><font color=#C00000">Susquehanna Speedway Park</font><br><small>Women on Wheels Mini Vans,<br>Trail Motors Super Sportsman,<br>Street Stocks & Legends Cars</small><br><br><font color="#C00000">Williams Grove Speedway</font><br><small>Sprints & ARDC Midgets</small><br><br><font color="#0000FF">Sat. May 13</font><br><font color="#C00000">Lincoln Speedway</font><br><small>410 Sprints, 358 Sprints & Thundercars</small><br><br><font color="#C00000">Port Royal Speedway</font><br><small>Sprints, Late Models,<br>Pro Stocks & Enduro Cars</small><br><br><font color="#C00000">Williams Grove Speedway</font><br><small>Super Sportsman,<br>Late Models & Street Stocks</small>';
    
    var boxheight=150; // BACKGROUND BOX HEIGHT IN PIXELS.
    var boxwidth=250; // BACKGROUND BOX WIDTH IN PIXELS.
    var boxcolor="#FFFFFF"; // 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);
    bgtrans();
    }
    </script>
    
    </td>
    <td bgcolor="#FFFFFF" align="center">&nbsp;</td>
    <td bgcolor="#FFFFFF" align="center">&nbsp;</td>
    </tr>
    </table>
    </div>
    
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    You deleted
    --><body onload="bgtrans()"><!--
    so that left only the one window.onload event.

  • #6
    New to the CF scene
    Join Date
    May 2006
    Location
    Mechanicsburg, PA
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you VERY much vwphillips. I really appreciate it. I tried so many different things and nothing worked.


  •  

    Posting Permissions

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