1

I have an Object called (rowdata) and in that object there are two concatenated values separated by "\n", I want to display the two values in listbox. One value one row, how to break the two concatenated values and display to listbox.

code:

var myArray = [[rowdata]]; // assuming rowdata have two value separated by \n in localstorage

function populate(){
for(i=0;i<myArray.length;i++){
var select = document.getElementById("test"); //ID of the listboxt
select.options[select.options.length] = new Option(myArray[i][0], myArray[i][1]);
}
}

Is there a way to do that? thank you

Toni
  • 11
  • 5

1 Answers1

0

Use split: http://www.w3schools.com/jsref/jsref_split.asp

Something like:

function populate(){
    for(i=0;i< rowdata.length;i++){
        var select = document.getElementById("test"); //ID of the listboxt
        var splitRow = rowData[i].split("\n");
        select.options[select.options.length] = new Option(splitRow[0], splitRow[1]);
    }
}
pfrank
  • 2,090
  • 1
  • 19
  • 26
  • I try your code but all the letter are display one by one, i need to display one word in one row and the second word into second row, by the way thank you, you give me some idea... – Toni Sep 15 '13 at 02:04
  • I'm expecting rowdata to be an array, is it just a string? What's in rowdata? – pfrank Sep 15 '13 at 06:03
  • no rowdata is a variable that have two value separated by \n but i figure out the answer i can now display the value one word in a row. – Toni Sep 15 '13 at 10:07
  • but the second problem is how to remove specific value in the localStorage, it hard to identify because the value is concatenated. can you please advise me what method i am going to apply, if you have example please provide a link and i will work it out...thanks advanced – Toni Sep 15 '13 at 10:13
  • Try to store the value as an encoded array, using JSON encoding/decoding. Check this out: http://stackoverflow.com/questions/3357553/how-to-store-an-array-in-localstorage – pfrank Sep 15 '13 at 18:10