Page 1 of 1

Populate selectmenu from localStorage !

Posted: Wed Jul 30, 2014 8:39 am
by Luci Emilian

How can I populate a select menu from localStorage variable ?

My localStorage variable looks like this :

server1;ip1
server2;ip2
server3;ip3
....

I wish the "Label" to be server1, server2, SERVER3 ... and "Value" to be IP1, IP2, IP3, ... to access selectmenu .

Thanks in advance !


Populate selectmenu from localStorage !

Posted: Wed Jul 30, 2014 8:49 am
by Evgene Karachevtsev

Hello Luci,

You should read the variable, break it into its component parts (https://developer.mozilla.org/en-US/d...), add options in select (http://api.jquery.com/category/manipu...)


Populate selectmenu from localStorage !

Posted: Wed Jul 30, 2014 9:45 am
by Luci Emilian

Ok , i split the local storage but i don't know to add this to the list .
Can you help me ?

var stringToSplit = localStorage.getItem('serverlist');
var arrayOfStrings = stringToSplit.split(';');

for (var i=0; i < arrayOfStrings.length-1; i++)
{
if (i%3===0)
{
var serverx = arrayOfStrings;
var ipx = arrayOfStrings[i+1];
var portx = arrayOfStrings[i+2];

Code: Select all

 var labelx = serverx; 
 var valuex= $.trim(ipx)+' '+$.trim(portx); 

     alert(labelx); // This must be add at selectmenu option label 
     alert(valuex); //This must be add at selectmenu option value 

 } 

}

Thanks !


Populate selectmenu from localStorage !

Posted: Wed Jul 30, 2014 10:35 am
by Luci Emilian

OK !
We found !

Appery("mobileselectmenuName").empty();
Appery("mobileselectmenuName").append($('' + 'Please select !' + ''));

Appery("mobileselectmenuName_44").selectmenu("refresh");


Populate selectmenu from localStorage !

Posted: Wed Jul 30, 2014 10:37 am
by Luci Emilian

OK!
We found it !

Appery("mobileselectmenuname").empty();
Appery("mobileselectmenuname").append($('' + 'Please select !' + ''));

Appery("mobileselectmenuname").selectmenu("refresh");


Populate selectmenu from localStorage !

Posted: Wed Jul 30, 2014 10:37 am
by Luci Emilian

Thanks !


Populate selectmenu from localStorage !

Posted: Wed Jul 30, 2014 10:38 am
by Evgene Karachevtsev

Luci,

Thank you for your update, glad it works!