Page 1 of 2

code error

Posted: Thu Oct 24, 2013 7:00 pm
by Michael4771079

Hi,

I am trying to save 4 values to localstorage array, I have used the static code I got for the selectmenu array. I have tried to alter the code for the event onclick. but its wrong, but I had to start somewhere, can you tell me whats wrong with the event code

this is the error in console

Image

static code

function save(item, varName) {
var arr = JSON.parse(localStorage.getItem(varName));
if(arr == null) {
arr = new Array();
}
arr.push(item);
localStorage.setItem(varName, JSON.stringify(arr))
}

function myload(varName) {
var arr = JSON.parse(localStorage.getItem(varName));
if(arr == null) {
arr = new Array();
}
return arr;
}

event on click

codesave({'Pizza':Tiggzi("chickenpizza_item_label").val(), 'Size':Tiggzi("orderlabel").val()},
'Base':Tiggzi("thin_deeptoggle").val()},
'Price':Tiggzi("chickenpizzaPricelabel").val()},
"liveoderArray");/code


code error

Posted: Thu Oct 24, 2013 7:34 pm
by Kateryna Grynko

Hi Michael,

There were some extra closing braces "}". Please try the following:
presave(
{'Pizza':Tiggzi("chickenpizza_item_label").val(), 'Size':Tiggzi("orderlabel").val(),
'Base':Tiggzi("thin_deeptoggle").val(),
'Price':Tiggzi("chickenpizzaPricelabel").val()},
"liveoderArray");/pre


code error

Posted: Thu Oct 24, 2013 8:15 pm
by Michael4771079

much better than my effort :) but still a problem, saves array, but no label values, got the toggle value

here is a screenshot

Image


code error

Posted: Thu Oct 24, 2013 8:51 pm
by Kateryna Grynko

Michael,

Please replace Tiggzi with Appery. This is an old construction.
In debugger, make sure the correct values are returned.


code error

Posted: Thu Oct 24, 2013 8:58 pm
by Michael4771079

No Katya, diddn't change anything, same as before

Image


code error

Posted: Thu Oct 24, 2013 10:54 pm
by Michael4771079

Hi,
I have made the change to the code Katya suggested above,
but the result is the array is saving to localstorage,
but no label values,
it has saved toggle value, although not the text I used for toggle,
and it always shows "on" irrespective of which way you set it in the tester

any ideas?

this is the localstorage result

Image


code error

Posted: Thu Oct 24, 2013 11:56 pm
by Igor

Hi,

You can add alert or console.log() to check what does Appery().value return.


code error

Posted: Fri Oct 25, 2013 12:11 am
by Michael4771079

Hi Igor,
where will I put this,
in the click event?

it this it
alert. appery().value return


code error

Posted: Fri Oct 25, 2013 12:17 am
by Igor

You should put it before "save" on "chickenorderbutton" click event.

pre
alert(Appery("chickenpizza_item_label").val());
/pre


code error

Posted: Fri Oct 25, 2013 12:23 am
by Michael4771079

Hi Igor,
this is the alert result, nothing at all

Image

I think the error must be in the static code below, Katya's correction of my event code made the array save, just no label values,

is my static code correct?

thx for your help here

codefunction save(item, varName) {
var arr = JSON.parse(localStorage.getItem(varName));
if(arr == null) {
arr = new Array();
}
arr.push(item);
localStorage.setItem(varName, JSON.stringify(arr))
}

function myload(varName) {
var arr = JSON.parse(localStorage.getItem(varName));
if(arr == null) {
arr = new Array();
}
return arr;
}
/code