/    Sign up×
Community /Pin to ProfileBookmark

Strange json parsed query behavior

I’m using jquery with my script, I have this function and this variable.

[code]
var page = 1;
var opciones = $.parseJSON(‘[[“cacona”,”caconudo”,”caca”,”weopo”],[“cacona”,”caca”,”weopoweopo”,”caconudo”],[“caca”,”weopo”,”cacona”,”caconudo”],[“cacona”,”caca”,”caconudo”,”weopoweopo”],[“caca”,”cacona”,”caconudo”,”weopo”],[“caca”,”cacona”,”caconudo”,”weopoweopo”],[“cacona”,”weopo”,”caca”,”caconudo”],[“caca”,”weopo”,”cacona”,”caconudo”],[“caca”,”caconudo”,”weopo”,”cacona”],[“cacona”,”weopo”,”caca”,”caconudo”]]’);

var preguntas = new Array(“¿Como me llamo?”, “¿Donde vivo?”, “¿En que barrio?”, “¿En que barrio?”, “¿En que barrio?”, “¿En que barrio?”, “¿En que barrio?”, “¿En que barrio?”, “¿En que barrio?”, “¿En que barrio?”);

function getActualContent() {
if(page == 3) {
iValue = 2;
}
else {
iValue = 4;
}
for(i=0;i<iValue;i++) {
actualValue = (i+(4*page)-4);
$(“#”+elementSelected[actualValue]).attr(“checked”, true);
$(“#preguntaText”+(i+1)).html(“Pregunta “+(actualValue+1)+”: “);
$(“#pregunta”+(i+1)+”Span”).html(preguntas[actualValue]);
for(j=0;j<4;j++) {
$(“#opcion”+(i+1)+”-“+(j+1)+”Span”).html(opciones[actualValue][j]);
}
}
}

$(“#back”).click(function() {
$(“#mainTable”).hide(“slide”, {direction: “right”}, 800, function() {
if(page == 3) {
$(“#secTable1”).show();
$(“#secTable2”).show();
}
saveActualContent();
page = page-1;
$(“#pageSpan”).html(page+”/3″);
cleanChecked();
getActualContent();
getAnchor();
});
$(“#mainTable”).show(“slide”, {direction: “left”}, 800);
});
[/code]

If I loop all over opciones, it shows correctly each value of the array, also when I go to the next page it still works, but it strangly fails when going back, it shows in firebug: undefined opciones[actualValue] in the function getActualContent and stats looping back, don’t know why.
Thanks in advice

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @lautarox spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...