PAC 2 PW 5.
by Rene Rubio
HTML
<div id="pregunta1">
<label for="pregunta">Pregunta 1</label>
<input type="text" id="q1" />
</div>
<div id="pregunta2" style="display:none">
<label for="pregunta">Pregunta 2</label>
<input type="text" id="q2" />
</div>
<div id="pregunta3" style="display:none">
<label for="pregunta">Pregunta 3</label>
<input type="text" id="q3" />
</div>
<!----------------------------------------->
<div id="respuesta1" style="display:none">
<label for="pregunta">Respuesta 1</label>
<input type="text" id="r1" />
</div>
<div id="respuesta2" style="display:none">
<label for="pregunta">Respuesta 2</label>
<input type="text" id="r2" />
</div>
<div id="respuesta3" style="display:none">
<label for="pregunta">Respuesta 1</label>
<input type="text" id="r3" />
</div>
<button type="button" id="enviar" >Enviar</button>
JavaScript
function validar( campo ){
var valor = document.getElementById(campo).value;
var valid = ( valor != '') ? true : false;
return valid;
}
function mostrar(){
document.getElementById('respuesta1').style.display = 'block';
validar();
}
var enviar = document.getElementById('enviar');
enviar.onclick = function(){
validar('q1') ? mostrar() : alert('el campo no puede estar vacĂo');
};