Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

code error

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

code error

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

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

code error

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

here is a screenshot

Image

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

code error

Michael,

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

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

code error

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

Image

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

code error

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

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

code error

Hi,

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

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

code error

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

it this it
alert. appery().value return

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

code error

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

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

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

code error

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

Return to “Issues”