She
Posts: 0
Joined: Wed Oct 08, 2014 12:46 am

localStorage to selectedoption in dropmenu

Hi Team,
I need help. How can i select the value of localStorage to dropdown box? without this:
Image

This is my code. when the service is successfully got the data from our php webservice and store it inside the select.:

var filterby = localStorage.getItem("FilterBy");
var filterbytext = localStorage.getItem("FilterByText");
Appery("sFilterby").find('option:selected').val(filterby);
Appery("sFilterby").find('option:selected').text(filterbytext);

Thanks in advance,

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

localStorage to selectedoption in dropmenu

Hello,

Please use code below:
pre
var filterby = localStorage.getItem("_FilterBy");
Apperyio("sFilterby").find("[value=" + filterby + "]").prop("selected", true);
Apperyio("sFilterby").refresh();
/pre

She
Posts: 0
Joined: Wed Oct 08, 2014 12:46 am

localStorage to selectedoption in dropmenu

Hi Sergiy,

Thank you for the fast respond, Nothing happen. when i put this code in complete event after getting the data from service.

But i tested this code to the hard coded options in select.
Image
its working perfect.

when i put the code in complete or success event. nothing is happen. screenshot is in below:

Image
mapping is:
Image

Thank you very much

She
Posts: 0
Joined: Wed Oct 08, 2014 12:46 am

localStorage to selectedoption in dropmenu

Hi Team,
I already get this problem i changed the PROP to ATTR. now the another problem that i encounter is when the program detects a "SPACE" on the localstorage.

there's new code for newlocal storage:

var filteritem = localStorage.getItem("_FilterItem");
Appery("sFilterItem").find("[value=" +filteritem+ "]").attr("selected", true);
Apperyio("sFilterItem").refresh();
New_FirstLoggedMapping.execute();

the localStorage has a value of "Admin Assistant"

but when the localstorage dont have "SPACE" the program works without an error. for example:
Sample1
Sample2
Sample3

when the localstorage has a value with a "SPACE" it didnt work. for example:

Sample 4
Sample 5

and the error that is showing is
Uncaught Error: Syntax error, unrecognized expression: [value=Admin Assistant]

Thank you,

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

localStorage to selectedoption in dropmenu

Just add extra quotes.
Change:
pre
Appery("sFilterItem").find("[value=" +filteritem+ "]").attr("selected", true);
/pre
to
pre
Appery("sFilterItem").find("[value='" +filteritem+ "']").attr("selected", true);
/pre

Return to “Issues”