Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/220698-strange-json-parsed-query-behavior/
Share on other sites

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..

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.