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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating select options from cookie str

Status
Not open for further replies.

LAwebTek

Programmer
Jan 23, 2003
13
0
0
US
the saveList() function works. I tried to write the loadList() function to repopulate the select options, but I'm obviously doing something wrong at the end of the code. In my test I save 3 items and when it repopulates it does create 3 options, however only the first option contains the proper text and value and the other 2 display undefined. Here's the code:

function saveList() {
var newList = document.amp.playlist.options;
var j, len = newList.length;
var Sngstr = "";
for (j = 0; j < len; j++) {
if (Sngstr.length > 0) Sngstr += &quot;&&quot;;
Sngstr += newList[j].value + &quot;|&quot; + newList[j].text;
}
setCookie (&quot;TheList&quot;,Sngstr,expdate);
}

function loadList() {
var i, j;
playList = document.amp.playlist.options;
TheList = getCookie(&quot;TheList&quot;);
if (TheList != null) {
listArray = TheList.split(&quot;&&quot;);
for (i = 0; i < listArray.length; i++) {
j = i + 1;
piecesArray = listArray.split(&quot;|&quot;);
//Below is where something seems to be wrong
var no = new Option();
no.value = piecesArray;
no.text = piecesArray[j];
playList[playList.length] = no;
}
}
}

Any ideas?
 
The problem is solved, but in case you want to know how it's done (thanks to Dave Clark of Dave Clark's consulting) it looks like this:

function loadList() {
var playList = document.amp.playlist.options;
var TheList = getCookie(&quot;TheList&quot;);
if (TheList != null) {
var listArray = TheList.split(&quot;&&quot;);
var j, v, len = listArray.length;
for (j=0; j<len; j++) {
v = listArray[j].split(&quot;|&quot;);
playList[playList.length] = new Option(v[1], v[0]);
}
}
}


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top