-1

Muy buenas. Estoy estudiando el primer año de DAW y mi profesor nos ha puesto como reto tocar un poco de Javascript. No lo he tocado nunca, investigando he encontrado algunas cosas, pero bueno, mi duda es que necesito hacer una página que permita realizar una matrícula en un curso, seleccionando el ciclo y los módulos del mismo. Hasta ahí todo bien, pero cuando tengo que seleccionar la modalidad (presencial / semipresencial) le quiero asignar un href que me redirija a unos módulos diferentes dependiendo del ciclo elegido, y sólo consigo que me redirija al ulimo if que pongo.

Código:

var refTitulo = document.getElementById("matricula");
var refModulo1 = document.getElementById("informatica");
var refModulo2 = document.getElementById("diseño");


function iniciarScript() {
  refTitulo;
}

function changeText() {
  refTitulo.style.display = "none";
  refModulo1.style.display = "";
  refModulo2.style.display = "";
}

function changeTextMod1() {
  document.getElementById("informatica").style.display = "none";
  document.getElementById("diseño").style.display = "none";
  document.getElementById("daw").style.display = "";
  document.getElementById("dam").style.display = "";
  document.getElementById("asir").style.display = "";
  document.getElementById("smr").style.display = "";
  document.getElementById("presencial").style.display = "none";
  document.getElementById("semipresencial").style.display = "none";
}

function changeTextMod2() {
  document.getElementById("presencial").style.display = "";
  document.getElementById("semipresencial").style.display = "";
  document.getElementById("informatica").style.display = "none";
  document.getElementById("diseño").style.display = "none";
  document.getElementById("daw").style.display = "none";
  document.getElementById("dam").style.display = "none";
  document.getElementById("asir").style.display = "none";
  document.getElementById("smr").style.display = "none";
}

window.onload = function () {
  function websiteBeoordelen() {
      var dawX = document.getElementsByTagName("span")[5].childNodes[0].nodeValue;
      var damX = document.getElementsByTagName("span")[6].childNodes[0].nodeValue;
      var asirX = document.getElementsByTagName("span")[7].childNodes[0].nodeValue;
      var smrX = document.getElementsByTagName("span")[8].childNodes[0].nodeValue;


      if (dawX) {
          window.location = document.getElementById('presencial').href = "daw.html";
          window.location = document.getElementById('semipresencial').href = "daw.html";
      }
      if (damX) {
          window.location = document.getElementById('presencial').href = "dam.html";
          window.location = document.getElementById('semipresencial').href = "dam.html";
      }
      if (asirX) {
          window.location = document.getElementById('presencial').href = "asir.html";
          window.location = document.getElementById('semipresencial').href = "asir.html";
      }
      if (smrX) {
          window.location = document.getElementById('presencial').href = "smr.html";
          window.location = document.getElementById('semipresencial').href = "smr.html";
      }
      /*else {
                 document.write("The code is wrong, try again!");
             } */
      return false;
  }
  document.getElementById('presencial').onclick = websiteBeoordelen;
  document.getElementById('semipresencial').onclick = websiteBeoordelen;
};

window.addEventListener("load", iniciarScript, true);
<head>
  <title>Plantilla HTML5</title>

  <meta name="description" content="Plantilla HTML5" />
  <meta name="keywords" content="HTML CSS JS JSON" />
  <link type="text/css" rel="stylesheet" href="css/app.css" />
  <link href="img/favicon.ico" rel="icon" type="image/x-icon" />
</head>
<body>
  <div>
      <span onclick="changeText()" id="matricula" style="display" name="matri">MATRICULACIÓN</span>
      <span onclick="changeTextMod1()" id="informatica" style="display:none;">INFORMÁTICA</span>
      <span id="diseño" onclick="changeTextMod2()" style="display:none;">DISEÑO 3D</span>
      <span id="presencial" style="display:none;">PRESENCIAL</span>
      <span id="semipresencial" style="display:none;">SEMIPRESENCIAL</span>

      <div>
          <span onclick="changeTextMod2()" id="daw" style="display:none;">DAW</span>
          <span onclick="changeTextMod2()" id="dam" style="display:none;">DAM</span>
          <span onclick="changeTextMod2()" id="asir" style="display:none;">ASIR</span>
          <span onclick="changeTextMod2()" id="smr" style="display:none;">SMR</span>
      </div>
  </div>
</body>

Espero que me podáis ayudar porque voy perdidísimo de verdad.

1 respuesta 1

-2

<html!>
<head>
  <title>Entregable DAW </title>
  <meta name="description" content="DAW HTML5" />
  <meta name="keywords" content="HTML CSS JS JSON" />
  <link type="text/css" rel="stylesheet" href="css/app.css" />
  <link href="img/favicon.ico" rel="icon" type="image/x-icon" />
  <script type="text/javascript" >
		var Semi = "";
		var Pres = "";
		function changeText() {
		  document.getElementById("matricula").style.display = "none";
		  document.getElementById("informatica").style.display = "";
		  document.getElementById("diseño").style.display = "";
		}
		function changeTextMod1() {
		  document.getElementById("informatica").style.display = "none";
		  document.getElementById("diseño").style.display = "none";
		  document.getElementById("daw").style.display = "";
		  document.getElementById("dam").style.display = "";
		  document.getElementById("asir").style.display = "";
		  document.getElementById("smr").style.display = "";
		  document.getElementById("presencial").style.display = "none";
		  document.getElementById("semipresencial").style.display = "none";
		}
		function changeTextMod2() {
		  document.getElementById("presencial").style.display = "";
		  document.getElementById("semipresencial").style.display = "";
		  document.getElementById("informatica").style.display = "none";
		  document.getElementById("diseño").style.display = "none";
		  document.getElementById("daw").style.display = "none";
		  document.getElementById("dam").style.display = "none";
		  document.getElementById("asir").style.display = "none";
		  document.getElementById("smr").style.display = "none";
		}
		function daw() {
		  Semi = "/daw.html";
		  Pres = "/daw.html";
		}
		function dam() {
		  Semi = "/dam.html";
		  Pres = "/dam.html";
		}
		function asir() {
		  Semi = "/asir.html";
		  Pres = "/asir.html";
		}
		function smr() {
		  Semi = "/smr.html";
		  Pres = "/smr.html";
		}
		function pres() {window.location.href = Pres;}
		function semi() { window.location.href = Pres;}
</script>
</head>
<body>
  <div>
      <span onclick="changeText()" id="matricula" style="display" name="matri">MATRICULACIÓN</span>
      <span onclick="changeTextMod1()" id="informatica" style="display:none;">INFORMÁTICA</span>
      <span id="diseño" onclick="changeTextMod2()" style="display:none;">DISEÑO 3D</span>
      <span id="presencial" onclick="pres()" style="display:none;">PRESENCIAL</span>
      <span id="semipresencial" onclick="semi()" style="display:none;">SEMIPRESENCIAL</span>
      <div>
          <span onclick="changeTextMod2()" id="daw" style="display:none;">DAW</span>
          <span onclick="changeTextMod2()" id="dam" style="display:none;">DAM</span>
          <span onclick="changeTextMod2()" id="asir" style="display:none;">ASIR</span>
          <span onclick="changeTextMod2()" id="smr" style="display:none;">SMR</span>
      </div>
  </div>
</body>
</html>

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.