Results 1 to 3 of 3

Thread: Javascript code that needs a little help

  1. #1
    Join Date
    Nov 2007
    Posts
    18
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Javascript code that needs a little help

    The following code is used by our radio station website to display the current song and artist playing on our station on our website. We would like to show the last 10 songs that played. Our broadcast software will only send out the current song playing. So somehow we need to edit the code below so it will remember the last 10 songs.

    Thanks for your help! I'm great at HTML but that's about it.

    http://stuwww.hsu.edu/kswh/code.txt

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    to get you started

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    /*<![CDATA[*/
    
    function Save(frm,nme,nu,days){
     for (var flds=frm[nme],v='',z0=0;z0<flds.length;z0++){
      v+=flds[z0].value+'^';
     }
     AddToList(v,nu,days);
    }
    
    function AddToList(v,nu,days){
     var Cookie=zxcReadCookie('nme1');
     if (!Cookie){
      zxcCreateCookie('nme1',v+'#',days);
     }
     else {
      var cv=Cookie.split('#');
      for (var z0=0;z0<cv.length;z0++){
       if (cv[z0]==v) return;
      }
      Cookie=v+'#'+Cookie
      cv=Cookie.split('#');
      cv.length=Math.min(cv.length,nu+1);
      zxcCreateCookie('nme1',cv.join('#'),days);
     }
    }
    
    function zxcCreateCookie(nme,v,days){
     document.cookie=nme+'='+v+';expires='+(new Date(new Date().getTime()+days*86400000).toGMTString())+';path=/';
    }
    
    function zxcReadCookie(nme){
     nme+='=';
     var split = document.cookie.split(';');
     for(var z0=0;z0<split.length;z0++){
      var s=split[z0];
      while (s.charAt(0)==' ') s=s.substring(1,s.length);
      if (s.indexOf(nme)==0) return s.substring(nme.length,s.length);
     }
     return null;
    }
    
    function List(){
     var Cookie=zxcReadCookie('nme1');
     if (Cookie){
      var ta=document.forms[0].ta;
      Cookie=Cookie.split('#');
      for (var v,z0=0;z0<Cookie.length-1;z0++){
       v=Cookie[z0].split('^');
       ta.value+=v[0]+' - '+v[1]+' - '+v[2]+' - '+'\n';
      }
    
     }
    
    }
    /*]]>*/
    </script></head>
    
    <body onload="List();">
    <form name="myform" >
    <input name="tst[]" /><input name="tst[]" /><input name="tst[]" /> <br />
    <input type="button" name="" value="Save 10" onclick="Save(this.form,'tst[]',10,1);" /><br />
    <textarea name="ta" rows="10" cols="20"></textarea>
    </form>
    </body>
    
    </html>

  3. #3
    Join Date
    Nov 2007
    Posts
    18
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    how does this script know where the xml file is?

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
  •