• Viernes 29 de Marzo de 2024, 13:42

Autor Tema:  Encuesta JavaScript Con XML  (Leído 2382 veces)

Marshmallow

  • Nuevo Miembro
  • *
  • Mensajes: 1
    • Ver Perfil
Encuesta JavaScript Con XML
« en: Viernes 27 de Mayo de 2011, 12:59 »
0
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
  1. function cargar() {
  2.     var DocumentoXml = new ActiveXObject("Microsoft.XMLDOM");
  3.     DocumentoXml.async = false;
  4.  
  5.     DocumentoXml.load("Encuesta.xml");
  6.  
  7.     var estado = DocumentoXml.readyState;
  8.     var errorcin = DocumentoXml.parseError;
  9.  
  10.     var num = new Array();
  11.     var Pregunta = new Array();
  12.     var Tipo = new Array();
  13.     var aciertos = 0;
  14.  
  15.     if (errorcin.errorCode == 0)                                // Si no hay errores leyendo y cargando el documento XML
  16.     {
  17.         raiz = DocumentoXml.documentElement;
  18.  
  19.         for (i = 0; i < raiz.childNodes.length; i++)
  20.         {
  21.             Tipo[i] = raiz.childNodes(i).childNodes(0).text;
  22.             Pregunta[i] = raiz.childNodes(i).childNodes(1).text;
  23.  
  24.  
  25.             if (Tipo[i] == "Numerico")                          // Si la pregunta es de tipo Numerico
  26.             {
  27.  
  28.                 document.getElementById("Preguntas").innerHTML += "<div id='Preguntas" + i + "'>" + Pregunta[i] + "<br/>Decepcionante... " +
  29.               " 1 <input id='radio1" + i + "'type='radio' name ='radio" + i + "' value = '1'/>" +
  30.               " 2 <input id='radio2" + i + "'type='radio' name ='radio" + i + "' value = '2'/>" +
  31.               " 3 <input id='radio3" + i + "'type='radio' name ='radio" + i + "' value = '3'/>" +
  32.               " 4 <input id='radio4" + i + "'type='radio' name ='radio" + i + "' value = '4'/>" +
  33.               " 5 <input id='radio5" + i + "'type='radio' name ='radio" + i + "' value = '5'/>" + " ...Excelente </div><br/>";
  34.             }
  35.             else                                                // Si la pregunta es de tipo Texto
  36.             {
  37.                 document.getElementById("Preguntas").innerHTML += Pregunta[i] + " <textarea id='TextArea1' cols='20' name='S1' rows='2' ></textarea></div>";
  38.             }
  39.         }
  40.         document.getElementById("Preguntas").innerHTML += "<input type='button' id='boton' onclick='comprobar()' value='Enviar'>";
  41.     }
  42.    
  43.     else
  44.     {
  45.         alert("No se puede cargar la encuesta");
  46.     }
  47.  
  48. }
  49.  

Ya he conseguido que me salgan las preguntas por pantalla. Ahora me falta, guardar las respuestas en un arcivo XML...