PDA

View Full Version : Javascript code that needs a little help



reddiestorm
02-07-2009, 09:02 PM
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

vwphillips
02-08-2009, 04:26 PM
to get you started


<!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>

reddiestorm
02-08-2009, 06:03 PM
how does this script know where the xml file is?