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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how can i use same set of script once again? scared :(

    hello,
    i have one <script> </script> for text scroller... i want to place two scrollers in index page alone... if i copy and pasted the same code in another location then only one <script> block alone working.. how can i use same scroller script in two places?

    here is the script:
    Code:
    <script language="JavaScript1.2">
    
    
    // Scrollers width here (in pixels)
    var scrollerwidth="200px"
    
    // Scrollers height here
    var scrollerheight="100px"
    
    // Scrollers speed here (larger is faster 1-10)
    var scrollerspeed=1
    
    
    
    // Scrollers content goes here! Keep all of the message on the same line!
    <?php
    $sql = "SELECT * FROM `showcase` WHERE `active`='Y'";
    $pass = mysql_query($sql);
    $num = mysql_num_rows($pass);
    $content = "";
    for($i=1;$i<=$num;$i++)
    {
    $row = mysql_fetch_array($pass);
    $title = stripslashes($row['title']);
    $link = stripslashes($row['link']);
    $text = stripslashes($row['text']);
    $image = stripslashes($row['image']);
    $image = "admin/".$image;
    $content .= '<center><font face="Arial" color="white" size="3"><b>'.title.'</b><p><a href="'.$link.'">'.$link.'</a> <br> <img src="'.$image.'" > <br>'.$text.'</font><center>';
    }
    ?>
    var scrollercontent='<?php echo($content); ?>'
    
    var pauseit=1
    
    
    // Change nothing below!
    
    scrollerspeed=(document.all)? scrollerspeed : Math.max(1, scrollerspeed-1) //slow speed down by 1 for NS
    var copyspeed=scrollerspeed
    var iedom=document.all||document.getElementById
    var actualheight=''
    var cross_scroller, ns_scroller
    var pausespeed=(pauseit==0)? copyspeed: 0
    
    function populate(){
    if (iedom){
    cross_scroller=document.getElementById? document.getElementById("iescroller") : document.all.iescroller
    cross_scroller.style.top=parseInt(scrollerheight)+8+"px"
    cross_scroller.innerHTML=scrollercontent
    actualheight=cross_scroller.offsetHeight
    }
    else if (document.layers){
    ns_scroller=document.ns_scroller.document.ns_scroller2
    ns_scroller.top=parseInt(scrollerheight)+8
    ns_scroller.document.write(scrollercontent)
    ns_scroller.document.close()
    actualheight=ns_scroller.document.height
    }
    lefttime=setInterval("scrollscroller1()",20)
    }
    window.onload=populate
    
    function scrollscroller1(){
    
    if (iedom){
    if (parseInt(cross_scroller.style.top)>(actualheight*(-1)+8))
    cross_scroller.style.top=parseInt(cross_scroller.style.top)-copyspeed+"px"
    else
    cross_scroller.style.top=parseInt(scrollerheight)+8+"px"
    }
    else if (document.layers){
    if (ns_scroller.top>(actualheight*(-1)+8))
    ns_scroller.top-=copyspeed
    else
    ns_scroller.top=parseInt(scrollerheight)+8
    }
    }
    
    if (iedom||document.layers){
    with (document){
    if (iedom){
    write('<div style="position:relative;width:'+scrollerwidth+';height:'+scrollerheight+';overflow:hidden" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=scrollerspeed">')
    write('<div id="iescroller" style="position:absolute;left:0px;top:0px;width:100%;">')
    write('</div></div>')
    }
    else if (document.layers){
    write('<ilayer width='+scrollerwidth+' height='+scrollerheight+' name="ns_scroller">')
    write('<layer name="ns_scroller2" width='+scrollerwidth+' height='+scrollerheight+' left=0 top=0 onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=scrollerspeed"></layer>')
    write('</ilayer>')
    }
    }
    }
    
    </script>
    I need to change the var scrollercontent in second block.. any one can help me???

    Thank you.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Basically it needs to be written in OO JavaScript or all of the variable names need to be changed.

    By copying and pasting that code is like having two people in the room named Fred. You call Fred you probably will get the one that is nearer to you to come. If they were named Fred and Bill, you would have no issues. Hence why Global variable suck!

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I changed all variable names and function names...

    here is the script1:
    Code:
     <script language="JavaScript1.2">
    
    
    // Scrollers width here (in pixels)
    var scrollerwidth="200px"
    
    // Scrollers height here
    var scrollerheight="100px"
    
    // Scrollers speed here (larger is faster 1-10)
    var scrollerspeed=1
    
    
    
    // Scrollers content goes here! Keep all of the message on the same line!
    <?php
    $sql = "SELECT * FROM `showcase` WHERE `active`='Y'";
    $pass = mysql_query($sql);
    $num = mysql_num_rows($pass);
    $content = "";
    for($i=1;$i<=$num;$i++)
    {
    $row = mysql_fetch_array($pass);
    $title = stripslashes($row['title']);
    $link = stripslashes($row['link']);
    $text = stripslashes($row['text']);
    $image = stripslashes($row['image']);
    $image = "admin/".$image;
    $content .= '<center><font face="Arial" color="white" size="3"><b>'.title.'</b><p><a href="'.$link.'">'.$link.'</a> <br> <img src="'.$image.'" > <br>'.$text.'</font><center>';
    }
    ?>
    var scrollercontent='<?php echo($content); ?>'
    
    var pauseit=1
    
    
    // Change nothing below!
    
    scrollerspeed=(document.all)? scrollerspeed : Math.max(1, scrollerspeed-1) //slow speed down by 1 for NS
    var copyspeed=scrollerspeed
    var iedom=document.all||document.getElementById
    var actualheight=''
    var cross_scroller, ns_scroller
    var pausespeed=(pauseit==0)? copyspeed: 0
    
    function populate(){
    if (iedom){
    cross_scroller=document.getElementById? document.getElementById("iescroller") : document.all.iescroller
    cross_scroller.style.top=parseInt(scrollerheight)+8+"px"
    cross_scroller.innerHTML=scrollercontent
    actualheight=cross_scroller.offsetHeight
    }
    else if (document.layers){
    ns_scroller=document.ns_scroller.document.ns_scroller2
    ns_scroller.top=parseInt(scrollerheight)+8
    ns_scroller.document.write(scrollercontent)
    ns_scroller.document.close()
    actualheight=ns_scroller.document.height
    }
    lefttime=setInterval("scrollscroller1()",20)
    }
    window.onload=populate
    
    function scrollscroller1(){
    
    if (iedom){
    if (parseInt(cross_scroller.style.top)>(actualheight*(-1)+8))
    cross_scroller.style.top=parseInt(cross_scroller.style.top)-copyspeed+"px"
    else
    cross_scroller.style.top=parseInt(scrollerheight)+8+"px"
    }
    else if (document.layers){
    if (ns_scroller.top>(actualheight*(-1)+8))
    ns_scroller.top-=copyspeed
    else
    ns_scroller.top=parseInt(scrollerheight)+8
    }
    }
    
    if (iedom||document.layers){
    with (document){
    if (iedom){
    write('<div style="position:relative;width:'+scrollerwidth+';height:'+scrollerheight+';overflow:hidden" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=scrollerspeed">')
    write('<div id="iescroller" style="position:absolute;left:0px;top:0px;width:100%;">')
    write('</div></div>')
    }
    else if (document.layers){
    write('<ilayer width='+scrollerwidth+' height='+scrollerheight+' name="ns_scroller">')
    write('<layer name="ns_scroller2" width='+scrollerwidth+' height='+scrollerheight+' left=0 top=0 onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=scrollerspeed"></layer>')
    write('</ilayer>')
    }
    }
    }
    
    </script>
    here is the script2:
    all var names will end with 'a'
    Code:
    <script language="JavaScript1.2">
    
    
    // Scrollers width here (in pixels)
    var scrollerwidtha="200px"
    
    // Scrollers height here
    var scrollerheighta="100px"
    
    // Scrollers speed here (larger is faster 1-10)
    var scrollerspeeda=1
    
    
    
    // Scrollers content goes here! Keep all of the message on the same line!
    <?php
    $sql = "SELECT * FROM `showcase` WHERE `active`='Y'";
    $pass = mysql_query($sql);
    $num = mysql_num_rows($pass);
    $content = "";
    for($i=1;$i<=$num;$i++)
    {
    $row = mysql_fetch_array($pass);
    $title = stripslashes($row['title']);
    $link = stripslashes($row['link']);
    $text = stripslashes($row['text']);
    $image = stripslashes($row['image']);
    $image = "admin/".$image;
    $content .= '<center><font face="Arial" color="white" size="3"><b>'.title.'</b><p><a href="'.$link.'">'.$link.'</a> <br> <img src="'.$image.'" > <br>'.$text.'</font><center>';
    }
    ?>
    var scrollercontenta='<?php echo($content); ?>'
    
    var pauseita=1
    
    
    // Change nothing below!
    
    scrollerspeeda=(document.all)? scrollerspeeda : Math.max(1, scrollerspeeda-1) //slow speed down by 1 for NS
    var copyspeeda=scrollerspeeda
    var iedoma=document.all||document.getElementById
    var actualheighta=''
    var cross_scrollera, ns_scrollera
    var pausespeeda=(pauseita==0)? copyspeeda: 0
    
    function populatea(){
    if (iedoma){
    cross_scrollera=document.getElementById? document.getElementById("iescroller") : document.all.iescroller
    cross_scrollera.style.top=parseInt(scrollerheighta)+8+"px"
    cross_scrollera.innerHTML=scrollercontenta
    actualheighta=cross_scrollera.offsetHeight
    }
    else if (document.layers){
    ns_scrollera=document.ns_scrollera.document.ns_scrollera2
    ns_scrollera.top=parseInt(scrollerheighta)+8
    ns_scrollera.document.write(scrollercontenta)
    ns_scrollera.document.close()
    actualheighta=ns_scrollera.document.height
    }
    lefttime=setInterval("scrollscroller2()",20)
    }
    window.onload=populatea
    
    function scrollscroller2(){
    
    if (iedoma){
    if (parseInt(cross_scrollera.style.top)>(actualheighta*(-1)+8))
    cross_scrollera.style.top=parseInt(cross_scrollera.style.top)-copyspeeda+"px"
    else
    cross_scrollera.style.top=parseInt(scrollerheighta)+8+"px"
    }
    else if (document.layers){
    if (ns_scrollera.top>(actualheighta*(-1)+8))
    ns_scrollera.top-=copyspeeda
    else
    ns_scrollera.top=parseInt(scrollerheighta)+8
    }
    }
    
    if (iedoma||document.layers){
    with (document){
    if (iedoma){
    write('<div style="position:relative;width:'+scrollerwidtha+';height:'+scrollerheighta+';overflow:hidden" onMouseover="copyspeeda=pausespeeda" onMouseout="copyspeeda=scrollerspeeda">')
    write('<div id="iescroller" style="position:absolute;left:0px;top:0px;width:100%;">')
    write('</div></div>')
    }
    else if (document.layers){
    write('<ilayer width='+scrollerwidtha+' height='+scrollerheighta+' name="ns_scrollera">')
    write('<layer name="ns_scrollera2" width='+scrollerwidtha+' height='+scrollerheighta+' left=0 top=0 onMouseover="copyspeeda=pausespeeda" onMouseout="copyspeeda=scrollerspeeda"></layer>')
    write('</ilayer>')
    }
    }
    }
    
    </script>
    Still it is not working

  • #4
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    You can not have two window.onloads. I did not look at the code, but bet it is there.

    You probably have something like:
    window.onload = fnca;
    window.onload = fncb;

    it should be

    window.onload = function(){
    fnca();
    fncb();
    }

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

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