Programación Web y Scripting > JavaScript
Encuesta JavaScript Con XML
(1/1)
Marshmallow:
Hola, muy buenas a todos!
Veréis, tengo que hacer una encuesta en JavaScript que lea datos de un archivo XML, cargarlas en arrays y mostrarlas por pantalla. Una vez contestadas, se deben guardar en otro archivo XML. Pues bien, voy un poco perdido.
He conseguido hacer algo, pero hace poco que he empezado y no se por donde podría seguir. Cualquier ayuda sería agradecida.
Muchas gracias.
Esto es lo que tengo hecho hasta ahora:
--- Código: Text ---function cargar() { var DocumentoXml = new ActiveXObject("Microsoft.XMLDOM"); DocumentoXml.async = false; DocumentoXml.load("Encuesta.xml"); var estado = DocumentoXml.readyState; var errorcin = DocumentoXml.parseError; var num = new Array(); var Pregunta = new Array(); var Tipo = new Array(); var aciertos = 0; if (errorcin.errorCode == 0) // Si no hay errores leyendo y cargando el documento XML { raiz = DocumentoXml.documentElement; for (i = 0; i < raiz.childNodes.length; i++) { Tipo[i] = raiz.childNodes(i).childNodes(0).text; Pregunta[i] = raiz.childNodes(i).childNodes(1).text; if (Tipo[i] == "Numerico") // Si la pregunta es de tipo Numerico { document.getElementById("Preguntas").innerHTML += "<div id='Preguntas" + i + "'>" + Pregunta[i] + "<br/>Decepcionante... " + " 1 <input id='radio1" + i + "'type='radio' name ='radio" + i + "' value = '1'/>" + " 2 <input id='radio2" + i + "'type='radio' name ='radio" + i + "' value = '2'/>" + " 3 <input id='radio3" + i + "'type='radio' name ='radio" + i + "' value = '3'/>" + " 4 <input id='radio4" + i + "'type='radio' name ='radio" + i + "' value = '4'/>" + " 5 <input id='radio5" + i + "'type='radio' name ='radio" + i + "' value = '5'/>" + " ...Excelente </div><br/>"; } else // Si la pregunta es de tipo Texto { document.getElementById("Preguntas").innerHTML += Pregunta[i] + " <textarea id='TextArea1' cols='20' name='S1' rows='2' ></textarea></div>"; } } document.getElementById("Preguntas").innerHTML += "<input type='button' id='boton' onclick='comprobar()' value='Enviar'>"; } else { alert("No se puede cargar la encuesta"); } }
Ya he conseguido que me salgan las preguntas por pantalla. Ahora me falta, guardar las respuestas en un arcivo XML...
Navegación
Ir a la versión completa