Hi
So I dont understand the "local storage" idea. My app do not require a login but there are some checkboxes that i want to store for that user.
Will local storage do the job?
Thank you
Hi Johnny,
Yes, but please please take into account that localStorage stores strings only. That is, you can store "0" and "1" as strings.
The following discussion may be helpful for work with checkboxes: https://getsatisfaction.com/apperyio/...
can I use this code below in a app? I dont get it to work. Sorry for dumb question!
Checkbox 1
Checkbox 2
Checkbox 3
Checkbox 4
Checkbox 5
SAVE
LOAD
var i, checkboxes = document.querySelectorAll('input[type=checkbox]');
function save() {
for (i = 0; i < checkboxes.length; i++) {
localStorage.setItem(checkboxes.value, checkboxes.checked);
}
}
function load_() {
for (i = 0; i < checkboxes.length; i++) {
checkboxes.checked = localStorage.getItem(checkboxes.value) === 'true' ? true:false;
}
}
http://jsfiddle.net/sQuEy/4/
Hello! You can use < code tag to post your code. You would also need to explain in more details where do you use this code, what are you trying to acheive and what exactly doesn't work?
http://docs.appery.io/getting-help/
Your code saves checkboxed on all loaded screens and uses checkbox value for localStorage variable name (there might be problem if checkbox values are the same). To save use the following code:
codevar checked = [];
Appery("mobilecheckboxgroupName").find("input:checked").each(function(){
checked.push($(this).attr("id"));
});
localStorage.setItem("mobilecheckboxgroupName_checked", JSON.stringify(checked));/code
to get:
codevar checked, i, len;
Appery("mobilecheckboxgroupName").find("input").each(function () {$(this).prop("checked", false);});
try {
checked = JSON.parse(localStorage.getItem("mobilecheckboxgroupName_checked"));
if ({}.toString.call(checked) !== "[object Array]") {
checked = [];
}
} catch ( e ) {
checked = [];
}
for (i = 0, len = checked.length; i < len; i++) {
try {
$("#" + checked).prop("checked", true);
} catch ( e ) {
}
}
Appery("mobilecheckboxgroupName").find("input").each(function () {$(this).checkboxradio("refresh");});/code
where mobilecheckboxgroupName - mobilecheckboxgroup name