Results 1 to 7 of 7

Thread: Conflicting Scripts

  1. #1
    Join Date
    Jun 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Conflicting Scripts

    I'm new to all this web designing, so i would appreciate some help. I've come across a problem..........i entered 2 different HTML sripts in my webpage and they don't work at the same time and only the one which is entered latter gets enabled whilst the former script gets disabled (the other scripts i enter work fine, it's only thse two). I'm guessing there is a conflict between the two, can ayone help ????

    ---------------------------------------------------------------------------------------
    Heres the HTML for the 1st one:

    <div id="tempholder"></div>
    <script language="JavaScript" src="dhtmllib.js"></script>
    <script language="JavaScript" src="scroller.js"></script>
    <script language="JavaScript">

    /*
    Mike's DHTML scroller (By Mike Hall)
    Last updated July 21st, 02' by Dynamic Drive for NS6 functionality
    For this and 100's more DHTML scripts, visit http://www.dynamicdrive.com
    */

    //SET SCROLLER APPEARANCE AND MESSAGES
    var myScroller1 = new Scroller(0, 0, 480, 32, 1, 5); //(xpos, ypos, width, height, border, padding)
    myScroller1.setColors("#006600", "#ccffcc", "#009900"); //(fgcolor, bgcolor, bdcolor)
    myScroller1.setFont("Verdana,Arial,Helvetica", 2);
    myScroller1.addItem("<b>Click here for <a href='http://dynamicdrive.com'>Dynamic Drive</a>, the net\'s #1 DHTML site!</b>");
    myScroller1.addItem("<b>Visit <a href='http://www.brainjar.com'>Brain Jar</a>, Mike\'s great coding site!</b>");
    myScroller1.addItem("<b>Looking for free JavaScripts? Visit <a href='http://javascriptkit.com'>JavaScript Kit.</a>");
    myScroller1.addItem("<b>Discuss and get help on web coding, at <a href='http://www.codingforums.com'>CodingForums.com</a></b>");

    //SET SCROLLER PAUSE
    myScroller1.setPause(2500); //set pause beteen msgs, in milliseconds

    function runmikescroll() {

    var layer;
    var mikex, mikey;

    // Locate placeholder layer so we can use it to position the scrollers.

    layer = getLayer("placeholder");
    mikex = getPageLeft(layer);
    mikey = getPageTop(layer);

    // Create the first scroller and position it.

    myScroller1.create();
    myScroller1.hide();
    myScroller1.moveTo(mikex, mikey);
    myScroller1.setzIndex(100);
    myScroller1.show();
    }

    window.onload=runmikescroll
    </script>
    <div id="placeholder" style="position:relative; width:420px; height:32px;"> </div>

    This is the HTML for the 2nd one:

    <style type="text/css">
    .matrix { font-family:Lucida Console, Courier, Monotype; font-size:10pt; text-align:center; width:10px; padding:0px; margin:0px;}
    </style>

    <script type="text/javascript" language="JavaScript">

    <!--
    var rows=11; // must be an odd number
    var speed=50; // lower is faster
    var reveal=2; // between 0 and 2 only. The higher, the faster the word appears
    var effectalign="default" //enter "center" to center it.

    /***********************************************
    * The Matrix Text Effect- by Richard Womersley (http://www.mf2fm.co.uk/rv)
    * This notice must stay intact for use
    * Visit http://www.dynamicdrive.com/ for full source code
    ***********************************************/

    var w3c=document.getElementById && !window.opera;;
    var ie45=document.all && !window.opera;
    var ma_tab, matemp, ma_bod, ma_row, x, y, columns, ma_txt, ma_cho;
    var m_coch=new Array();
    var m_copo=new Array();
    window.onload=function() {
    if (!w3c && !ie45) return
    var matrix=(w3c)?document.getElementById("matrix"):document.all["matrix"];
    ma_txt=(w3c)?matrix.firstChild.nodeValue:matrix.innerHTML;
    ma_txt=" "+ma_txt+" ";
    columns=ma_txt.length;
    if (w3c) {
    while (matrix.childNodes.length) matrix.removeChild(matrix.childNodes[0]);
    ma_tab=document.createElement("table");
    ma_tab.setAttribute("border", 0);
    ma_tab.setAttribute("align", effectalign);
    ma_tab.style.backgroundColor="#000000";
    ma_bod=document.createElement("tbody");
    for (x=0; x<rows; x++) {
    ma_row=document.createElement("tr");
    for (y=0; y<columns; y++) {
    matemp=document.createElement("td");
    matemp.setAttribute("id", "Mx"+x+"y"+y);
    matemp.className="matrix";
    matemp.appendChild(document.createTextNode(String.fromCharCode(160)));
    ma_row.appendChild(matemp);
    }
    ma_bod.appendChild(ma_row);
    }
    ma_tab.appendChild(ma_bod);
    matrix.appendChild(ma_tab);
    } else {
    ma_tab='<ta'+'ble align="'+effectalign+'" border="0" style="background-color:#000000">';
    for (var x=0; x<rows; x++) {
    ma_tab+='<t'+'r>';
    for (var y=0; y<columns; y++) {
    ma_tab+='<t'+'d class="matrix" id="Mx'+x+'y'+y+'">&nbsp;</'+'td>';
    }
    ma_tab+='</'+'tr>';
    }
    ma_tab+='</'+'table>';
    matrix.innerHTML=ma_tab;
    }
    ma_cho=ma_txt;
    for (x=0; x<columns; x++) {
    ma_cho+=String.fromCharCode(32+Math.floor(Math.random()*94));
    m_copo[x]=0;
    }
    ma_bod=setInterval("mytricks()", speed);
    }

    function mytricks() {
    x=0;
    for (y=0; y<columns; y++) {
    x=x+(m_copo[y]==100);
    ma_row=m_copo[y]%100;
    if (ma_row && m_copo[y]<100) {
    if (ma_row<rows+1) {
    if (w3c) {
    matemp=document.getElementById("Mx"+(ma_row-1)+"y"+y);
    matemp.firstChild.nodeValue=m_coch[y];
    }
    else {
    matemp=document.all["Mx"+(ma_row-1)+"y"+y];
    matemp.innerHTML=m_coch[y];
    }
    matemp.style.color="#33ff66";
    matemp.style.fontWeight="bold";
    }
    if (ma_row>1 && ma_row<rows+2) {
    matemp=(w3c)?document.getElementById("Mx"+(ma_row-2)+"y"+y):document.all["Mx"+(ma_row-2)+"y"+y];
    matemp.style.fontWeight="normal";
    matemp.style.color="#00ff00";
    }
    if (ma_row>2) {
    matemp=(w3c)?document.getElementById("Mx"+(ma_row-3)+"y"+y):document.all["Mx"+(ma_row-3)+"y"+y];
    matemp.style.color="#009900";
    }
    if (ma_row<Math.floor(rows/2)+1) m_copo[y]++;
    else if (ma_row==Math.floor(rows/2)+1 && m_coch[y]==ma_txt.charAt(y)) zoomer(y);
    else if (ma_row<rows+2) m_copo[y]++;
    else if (m_copo[y]<100) m_copo[y]=0;
    }
    else if (Math.random()>0.9 && m_copo[y]<100) {
    m_coch[y]=ma_cho.charAt(Math.floor(Math.random()*ma_cho.length));
    m_copo[y]++;
    }
    }
    if (x==columns) clearInterval(ma_bod);
    }

    function zoomer(ycol) {
    var mtmp, mtem, ytmp;
    if (m_copo[ycol]==Math.floor(rows/2)+1) {
    for (ytmp=0; ytmp<rows; ytmp++) {
    if (w3c) {
    mtmp=document.getElementById("Mx"+ytmp+"y"+ycol);
    mtmp.firstChild.nodeValue=m_coch[ycol];
    }
    else {
    mtmp=document.all["Mx"+ytmp+"y"+ycol];
    mtmp.innerHTML=m_coch[ycol];
    }
    mtmp.style.color="#33ff66";
    mtmp.style.fontWeight="bold";
    }
    if (Math.random()<reveal) {
    mtmp=ma_cho.indexOf(ma_txt.charAt(ycol));
    ma_cho=ma_cho.substring(0, mtmp)+ma_cho.substring(mtmp+1, ma_cho.length);
    }
    if (Math.random()<reveal-1) ma_cho=ma_cho.substring(0, ma_cho.length-1);
    m_copo[ycol]+=199;
    setTimeout("zoomer("+ycol+")", speed);
    }
    else if (m_copo[ycol]>200) {
    if (w3c) {
    mtmp=document.getElementById("Mx"+(m_copo[ycol]-201)+"y"+ycol);
    mtem=document.getElementById("Mx"+(200+rows-m_copo[ycol]--)+"y"+ycol);
    }
    else {
    mtmp=document.all["Mx"+(m_copo[ycol]-201)+"y"+ycol];
    mtem=document.all["Mx"+(200+rows-m_copo[ycol]--)+"y"+ycol];
    }
    mtmp.style.fontWeight="normal";
    mtem.style.fontWeight="normal";
    setTimeout("zoomer("+ycol+")", speed);
    }
    else if (m_copo[ycol]==200) m_copo[ycol]=100+Math.floor(rows/2);
    if (m_copo[ycol]>100 && m_copo[ycol]<200) {
    if (w3c) {
    mtmp=document.getElementById("Mx"+(m_copo[ycol]-101)+"y"+ycol);
    mtmp.firstChild.nodeValue=String.fromCharCode(160);
    mtem=document.getElementById("Mx"+(100+rows-m_copo[ycol]--)+"y"+ycol);
    mtem.firstChild.nodeValue=String.fromCharCode(160);
    }
    else {
    mtmp=document.all["Mx"+(m_copo[ycol]-101)+"y"+ycol];
    mtmp.innerHTML=String.fromCharCode(160);
    mtem=document.all["Mx"+(100+rows-m_copo[ycol]--)+"y"+ycol];
    mtem.innerHTML=String.fromCharCode(160);
    }
    setTimeout("zoomer("+ycol+")", speed);
    }
    }
    // -->
    </script>

    ---------------------------------------------------------------------------------------

    By the way i'm using Geocities Webpage Builder...

    - FreeThinker

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    This is a little more complicated than the usual onload event conflict. Try this:

    In the first script, where it says:
    Code:
    window.onload=runmikescroll
    get rid of that. In the second script, where it says:
    Code:
    window.onload=function() {
    add a line just below that so it looks like this:
    Code:
    window.onload=function() {
    runmikescroll();
    That should get it.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for your reply, i had a go at that but unfortunatley a script error message appears with the error showing as " Expected '}' ".

    If you paste the codes in Microsoft FrontPage maybe you can figure out how to solve this conflict.

    -FreeThinker

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I don't use front page. I did paste your code to a blank page and it was too incomplete to run. I just did a fresh install of both scripts from their demo pages and made my recommended modifications. Both are working on one page. Are you sure you installed both scripts properly to begin with? Things you may have missed:

    The scroller script belongs in the body and requires you download the external .js files and have them in the same directory as your html page.

    The Matrix script belongs in the head but, has one bit that goes in the body.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jun 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for trying, i really don't know what the problem is though....i mean both of them work fine when i activate them seperately, and they appear to be in the correct places but, the problem is they don't seem to work together.

    I think it has something to do with what you intially mentioned, the 'window.onload' function, as there also appears to be another script on my page that doesn't seem to be working alongside the scroll script, but when i change the 'window.onload' function on the scroll script around slightly the other script comes back up. That script has a 'onload' function too...

    <!--Place this script in the HEAD section.-->


    <script language="JavaScript">
    <!--

    // You may edit the message below.
    var startMsg = "Hello";

    var str = "";
    var msg = "";
    var leftMsg = "";


    function setMessage()
    {
    if (msg == "")
    {
    str = " ";
    msg = startMsg;
    leftMsg = "";
    }

    if (str.length == 1)
    {
    while (msg.substring(0, 1) == " ")
    {
    leftMsg = leftMsg + str;
    str = msg.substring(0, 1);
    msg = msg.substring(1, msg.length);
    }

    leftMsg = leftMsg + str;
    str = msg.substring(0, 1);
    msg = msg.substring(1, msg.length);

    for (var ii = 0; ii < 120; ii++)
    {
    str = " " + str;
    }
    }
    else
    str = str.substring(10, str.length);

    window.status = leftMsg + str;
    // This editable value (1000 = 1 second)
    // corresponds to the speed of the shooting
    // message.
    timeout = window.setTimeout('setMessage()',100);

    }
    // -->
    </script>

    <!--Update the BODY tag for the timer function.-->

    <!-- You may edit the BODY color. -->
    <BODY bgcolor="ffffff" onload="timeout = window.setTimeout('setMessage()',500);">
    <style>

    Sorry if i'm not making any sense.

    - Free Thinker
    Last edited by FreeThinker; 06-05-2005 at 12:31 AM.

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    No, you're making plenty of sense, that's exactly the sort of thing that could throw things off. Any onload event handler will cancel all previous onload events. So, what you can do is remove that event from the body tag and put in in with the others so that it now looks like this:
    Code:
    window.onload=function() {
    runmikescroll();
    timeout = window.setTimeout("setMessage()",500);
    and the body tag looks like this:
    HTML Code:
    <BODY bgcolor="ffffff">
    Now, something I may not have been as clear about as I should have. The original window.onload=function from the matrix script had a bunch of stuff in it. You shouldn't take any of that away. We are just adding these other calls in at the beginning of it so that it ends up looking like this:
    Code:
    window.onload=function() {
    runmikescroll();
    timeout = window.setTimeout('setMessage()',500);
    	if (!w3c && !ie45) return
      var matrix=(w3c)?document.getElementById("matrix"):document.all["matrix"];
      ma_txt=(w3c)?matrix.firstChild.nodeValue:matrix.innerHTML;
      ma_txt=" "+ma_txt+" ";
      columns=ma_txt.length;
      if (w3c) {
        while (matrix.childNodes.length) matrix.removeChild(matrix.childNodes[0]);
        ma_tab=document.createElement("table");
        ma_tab.setAttribute("border", 0);
        ma_tab.setAttribute("align", effectalign);
        ma_tab.style.backgroundColor="#000000";
        ma_bod=document.createElement("tbody");
        for (x=0; x<rows; x++) {
          ma_row=document.createElement("tr");
          for (y=0; y<columns; y++) {
            matemp=document.createElement("td");
            matemp.setAttribute("id", "Mx"+x+"y"+y);
            matemp.className="matrix";
            matemp.appendChild(document.createTextNode(String.fromCharCode(160)));
            ma_row.appendChild(matemp);
          }
          ma_bod.appendChild(ma_row);
        }
        ma_tab.appendChild(ma_bod);
        matrix.appendChild(ma_tab);
      } else {
        ma_tab='<ta'+'ble align="'+effectalign+'" border="0" style="background-color:#000000">';
        for (var x=0; x<rows; x++) {
          ma_tab+='<t'+'r>';
          for (var y=0; y<columns; y++) {
            ma_tab+='<t'+'d class="matrix" id="Mx'+x+'y'+y+'">&nbsp;</'+'td>';
          }
          ma_tab+='</'+'tr>';
        }
        ma_tab+='</'+'table>';
        matrix.innerHTML=ma_tab;
      }
      ma_cho=ma_txt;
      for (x=0; x<columns; x++) {
        ma_cho+=String.fromCharCode(32+Math.floor(Math.random()*94));
        m_copo[x]=0;
      }
      ma_bod=setInterval("mytricks()", speed);
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Jun 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Ok.......

    Basically what happened is that i entered the code you told me to enter and removed what you told me to but, the same error message came up as before ( Expected '}' ) , but, i had a feeling that it was something to do with that piece of code, so i rearranged the code you told me to enter, and inputted the following....

    window.onload=runmikescroll
    timeout = window.setTimeout("setMessage()",500);

    ......then hey presto.........it worked!! I really appreciate your help John, thanks alot for all the effort you put in, it was a good challenge solving ths problem.(As for the matrix script i decided not to include that in my webpage anymore but, just in case i change my mind i know which thread to refer to)

    -Free Thinker

Bookmarks

Posting Permissions

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