NaDa Posted April 26, 2012 at 06:29 PM Report #451627 Posted April 26, 2012 at 06:29 PM Boas, Tenho aqui um projecto e numa parte dele, é para fazer um questionário em javascript.. Mas com um botão pergunta seguinte.. em vez da forma de lista e seleccionar a que queremos.. em vez disso pergunta á pergunta ao carregar num botao. E no fim dar o numero de perguntar certas e erradas. Alguém me podia dar um exemplo? Para adaptar ao que pretendo.. Desde já muito obrigado 🙂
ruiFernandes Posted April 26, 2012 at 07:23 PM Report #451634 Posted April 26, 2012 at 07:23 PM Boas, podes usar algo deste género como fiz agora aqui <html> <head><title>Questionario</title> <script type="text/javascript"> var maxPerguntas = 5; function aoCarregar(){ escondeTudo(); document.getElementById('pergunta1').style.display = "block"; document.getElementById('perguntaActual').value = 1; } function escondeTudo(){ for( i = 1; i <= maxPerguntas; i++){ document.getElementById('pergunta'+i).style.display = "none"; } } function perguntaAnterior(){ actual = document.getElementById('perguntaActual').value; if(actual > 1){ escondeTudo(); document.getElementById('perguntaActual').value--; document.getElementById('pergunta'+document.getElementById('perguntaActual').value).style.display = "block"; } } function proximaPergunta(){ actual = document.getElementById('perguntaActual').value; if(actual >= 1 && actual < maxPerguntas){ escondeTudo(); document.getElementById('perguntaActual').value++; document.getElementById('pergunta'+document.getElementById('perguntaActual').value).style.display = "block"; } } </script> </head> <body onload="javascript:aoCarregar();"> <a href="javascript:perguntaAnterior();">Pergunta anterior</a> <a href="javascript:proximaPergunta();">Pergunta seguinte</a> <hr/> <input type="hidden" id="perguntaActual" value=""/><br /> <div id="pergunta1">Pergunta 1!</div> <div id="pergunta2">Pergunta 2!</div> <div id="pergunta3">Pergunta 3!</div> <div id="pergunta4">Pergunta 4!</div> <div id="pergunta5">Pergunta 5!</div> </body> </html> espero ter ajudado 🙂 Cumprimentos, Rui Fernandes - Rui Fernandes
NaDa Posted April 26, 2012 at 10:01 PM Author Report #451657 Posted April 26, 2012 at 10:01 PM Muito obrigado isso vai me fazer poupar muito tempo ^^ Simples e eficaz, mesmo o que queria. Só adicionar a verificação das respostas e ta feito.. Podem fechar.. Mais uma vez obrigado 🙂
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now