Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

list options via cookieArray

Status
Not open for further replies.

LAwebTek

Programmer
Jan 23, 2003
13
US
I have been working on a project that will create a playlist of MP3,wav,midi, or au files and play them through the bgSound.src attribute. The script grabs the file path and filename of the audio file and saves it as the option value in the playlist and also grabs only the filename and uses it as the corresponding text for the option. Everything works great except that I can not figure out how to save the list and reload it. The entire [relevant] code is below - saveThe(playList) and loadThe(playList) are the functions that do not work. Please help!

function Play() {
playList = document.amp.playlist;
for(var i = 0; i < playList.options.length; i++) {
document.all.sound.src = playList.options.value;
}
}

function Stop() {
document.all.sound.src = &quot;&quot;;
}

function getCookie (name) {
var dcookie = document.cookie;
var cname = name + &quot;=&quot;;
var clen = dcookie.length;
var cbegin = 0;
while (cbegin < clen) {
var vbegin = cbegin + cname.length;
if (dcookie.substring(cbegin, vbegin) == cname) {
var vend = dcookie.indexOf (&quot;;&quot;, vbegin);
if (vend == -1) vend = clen;
return unescape(dcookie.substring(vbegin, vend));
}
cbegin = dcookie.indexOf(&quot; &quot;, cbegin) + 1;
if (cbegin == 0) break;
}
return null;
}

function setCookie (name, value, expires) {
if (!expires) expires = new Date();
document.cookie = name + &quot;=&quot; + escape (value) +
&quot;; expires=&quot; + expires.toGMTString() + &quot;; path=/&quot;;
}

function setCookieArray(name){
this.length = setCookieArray.arguments.length - 1;
for (var i = 0; i < this.length; i++) {
this[i + 1] = setCookieArray.arguments[i + 1]
setCookie (name + i, this[i + 1], expdate);
}
}

function getCookieArray(name){
var i = 0;
while (getCookie(name + i) != null) {
this[i + 1] = getCookie(name + i);
i++; this.length = i;
}
}

var expdate = new Date();
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 365));

function addTitle() {
title = document.Asound.file.value;
title = title.toLowerCase();
tl = title;
char = unescape(&quot;%5C&quot;);
while(tl.indexOf(char) != -1) {
pos = tl.indexOf(char);
tl = tl.substring(pos + 1, tl.length);
}
document.amp.title.value = tl;
}

var soundFile;
var songName;
var playList;
function move(soundFile,songName) {
soundFile = document.Asound.file.value;
songName = document.amp.title.value;
playList = document.amp.playlist;
var i = 0;
if(soundFile.value != &quot;&quot;) {
var no = new Option();
no.value = soundFile;
no.text = document.amp.title.value;
playList.options[playList.options.length] = no;
document.amp.title.value = &quot;&quot;;
}
}
function remove(playList) {
playList = document.amp.playlist;
for(var i=0; i<playList.options.length; i++) {
if(playList.options.selected && playList.options != &quot;&quot;) {
playList.options.value = &quot;&quot;;
playList.options.text = &quot;&quot;;
}
}
BumpUp(playList);
}
function BumpUp(playList) {
for(var i = 0; i < playList.options.length; i++) {
if(playList.options.value == &quot;&quot;) {
for(var j = i; j < playList.options.length - 1; j++) {
playList.options[j].value = playList.options[j + 1].value;
playList.options[j].text = playList.options[j + 1].text;
}
var ln = i;
break;
}
}
if(ln < playList.options.length) {
playList.options.length -= 1;
BumpUp(playList);
}
}
function Moveup(playList) {
playList = document.amp.playlist;
for(var i = 0; i < playList.options.length; i++) {
if (playList.options.selected && playList.options != &quot;&quot;
&& playList.options != playList.options[0]) {
var tmpval = playList.options.value;
var tmpval2 = playList.options.text;
playList.options.value = playList.options[i - 1].value;
playList.options.text = playList.options[i - 1].text
playList.options[i-1].value = tmpval;
playList.options[i-1].text = tmpval2;
}
}
}
function Movedown(playList) {
playList = document.amp.playlist;
for(var i = 0; i < playList.options.length; i++) {
if (playList.options.selected && playList.options != &quot;&quot;
&& playList.options[i+1] != playList.options[playList.options.length]) {
var tmpval = playList.options.value;
var tmpval2 = playList.options.text;
playList.options.value = playList.options[i+1].value;
playList.options.text = playList.options[i+1].text
playList.options[i+1].value = tmpval;
playList.options[i+1].text = tmpval2;
}
}
}
//this function doesnt work
function saveThe(playList) {
playList = document.amp.playlist;
for(var i = 0; i < playList.options.length; i++) {
newVal = new Array;
newVal = playList.options;
var listArray = new setCookieArray(&quot;TheList&quot;, // cookie name
newVal);

var listArray = new getCookieArray(&quot;TheList&quot;);
}
}
//neither does this one
function loadThe(playList) {
reSET();
getCookie(&quot;TheList&quot;);
var i, j;
playList = document.amp.playlist;
listArray = new getCookieArray(&quot;TheList&quot;);
if (listArray != null) {
for (i = 0; i < listArray.length; i++) {
playList.options[j] = new Option(listArray);
j++;
}
}
}

function reSET() {
listArray = null;
newVal = null;
}

<form name=&quot;amp&quot;>
<select name=&quot;playlist&quot; size=&quot;19&quot; class=&quot;plst&quot;></select>

<input type=&quot;text&quot; name=&quot;title&quot; size=&quot;35&quot;>

<input type=&quot;button&quot; value=&quot;Add&quot; onclick=&quot;move(soundFile,playList)&quot;>
<input type=&quot;button&quot; value=&quot;Remove&quot; onclick=&quot;remove(playList)&quot;>
<input type=&quot;button&quot; value=&quot;Up&quot; onclick=&quot;Moveup(playList)&quot;>
<input type=&quot;button&quot; value=&quot;Down&quot; onclick=&quot;Movedown(playList)&quot;>
<input type=&quot;button&quot; value=&quot;Save&quot; onclick=&quot;saveThe(playList)&quot;>
<input type=&quot;button&quot; value=&quot;Play&quot; onclick=&quot;Play()&quot;>
<input type=&quot;button&quot; value=&quot;Stop&quot; onclick=&quot;Stop()&quot;>
<input type=&quot;button&quot; value=&quot;Load&quot; onclick=&quot;loadThe(playList)&quot;>
</form>

<form name=&quot;Asound&quot;>
<input type=&quot;file&quot; name=&quot;file&quot; onBlur='addTitle()'>
</form>

Any help would be tremendous! Thanks in advance if you spend any time working on this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top