I'm trying to do a quiz and I want one question to appear at a time. I used the css property display: none;
to hide, and created a function in javascript that receives as a parameter the id of the div that has to be shown. Clicking% w /% of Start will show the first question. Then I call the function again by clicking button
Submit to show the next question, but it does not appear.
Ps: I just want to use javascript
function show_question (n) {
//Esconde o button start
document.getElementById('start').style.display = 'none';
//Mostrar a pergunta
document.getElementById(n).style.display = 'inline';
}
.question_form {
display: none;
}
<main>
<button id="start" onclick="show_question('q1')">Start</button>
<div class="question_form" id="q1">
<form id="question1">
<h3>1. Which tag should used to represent the "header" of a document?</h3>
<ul>
<li><input type="radio" name="q1" value="a">head</li>
<li><input type="radio" name="q1" value="b">header</li>
<li><input type="radio" name="q1" value="c">heading</li>
<li><input type="radio" name="q1" value="d">main</li>
</ul>
<button type="submit" id="btn-salvar" onclick="show_question('q2')">Submit</button>
</form>
</div>
<div class="question_form" id="q2">
<form id="quetion2">
<h3>2. Which the following is a NOT feature of HTML?<h3>
<ul>
<li><input type="radio" name="q2" value="a">New Media Elements</li>
<li><input type="radio" name="q2" value="b">Form Input Types</li>
<li><input type="radio" name="q2" value="c">Local Storage</li>
<li><input type="radio" name="q2" value="d">Cookies</li>
</ul>
<button id="submit" onclick="show_question('q3')">Submit</button>
</form>
</div>
<div class="question_form" id="q3">
<form id="question3">
<h3>3. Which element is the most appropriate to wrap around each blog post on a page?</h3>
<ul>
<li><input type="radio" name="q3" value="a">section</li>
<li><input type="radio" name="q3" value="b">post</li>
<li><input type="radio" name="q3" value="c">article</li>
<li><input type="radio" name="q3" value="d">main</li>
</ul>
<button id="submit">Submit</button>
</form>
</div>