Lautarox Posted December 5, 2010 Share Posted December 5, 2010 I'm using jquery with my script, I have this function and this variable. 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); }); 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 Quote Link to comment https://forums.phpfreaks.com/topic/220698-strange-json-parsed-query-behavior/ Share on other sites More sharing options...
haku Posted December 5, 2010 Share Posted December 5, 2010 Do you have a live version of the page? Issues like this can be tricky to debug with code alone. Quote Link to comment https://forums.phpfreaks.com/topic/220698-strange-json-parsed-query-behavior/#findComment-1143081 Share on other sites More sharing options...
Lautarox Posted December 5, 2010 Author Share Posted December 5, 2010 Thanks a lot for answering, I have a live page to show you, http://fbapplications.com.ar/test.html , I've made a lot of loggin so you can check what's going on easily Quote Link to comment https://forums.phpfreaks.com/topic/220698-strange-json-parsed-query-behavior/#findComment-1143198 Share on other sites More sharing options...
Lautarox Posted December 5, 2010 Author Share Posted December 5, 2010 This is really strange, have a look at this output: Trying to go to the next page from page: 1 to 2 Starting to save content from actual page: 1 Actual value: 0 - elecciones[0] = (1) - elementSelected[0] = (opcion1-1) Actual value: 1 - elecciones[1] = (1) - elementSelected[1] = (opcion2-1) Actual value: 2 - elecciones[2] = (1) - elementSelected[2] = (opcion3-1) Actual value: 3 - elecciones[3] = (1) - elementSelected[3] = (opcion4-1) And then, when triying to load it again: Starting to put content from page 1 actualValue=0 elementSelected[0] = opcion1-1 opciones[0][0] = cacona opciones[0][1] = caconudo opciones[0][2] = caca opciones[0][3] = weopo actualValue=1 elementSelected[1] = opcion2-1 opciones[1][0] = cacona opciones[1][1] = caca opciones[1][2] = weopoweopo opciones[1][3] = caconudo actualValue=2 elementSelected[2] = opcion3-1 opciones[2][0] = caca opciones[2][1] = weopo opciones[2][2] = cacona opciones[2][3] = caconudo actualValue=3 elementSelected[3] = [object Object] And it starts looping pages, something really strange. I don't know wht its value it's an object.. Quote Link to comment https://forums.phpfreaks.com/topic/220698-strange-json-parsed-query-behavior/#findComment-1143415 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.