I am very new to JavaScript and i'm struggling to find a solution to simplify my JavaScript code. I have working code, but it's very bulky and i feel like it can be made smaller or easier. Do you guys think it's possible?
I have went online and tried to see if i can implement what people have done, but most of the stuff either don't work or works but is not what i'm looking for.
<html>
<script>
window.onload = function () {
document.getElementById("Yes1").onclick = function () {
document.getElementById("Question1").style.display = 'None';
document.getElementById("Question2").style.display = 'inline';
}
document.getElementById("No1").onclick = function () {
document.getElementById("Question1").style.display = 'None';
document.getElementById("Question3").style.display = 'inline';
}
document.getElementById("Yes2").onclick = function () {
document.getElementById("Question2").style.display = 'None';
document.getElementById("Question4").style.display = 'inline';
}
document.getElementById("No2").onclick = function () {
document.getElementById("Question2").style.display = 'None';
document.getElementById("Question5").style.display = 'inline';
}
document.getElementById("Yes3").onclick = function () {
document.getElementById("Question3").style.display = 'None';
document.getElementById("Question6").style.display = 'inline';
}
document.getElementById("No3").onclick = function () {
document.getElementById("Question3").style.display = 'None';
document.getElementById("Question6").style.display = 'inline';
}
document.getElementById("Yes4").onclick = function () {
document.getElementById("Question4").style.display = 'None';
document.getElementById("Question10").style.display = 'inline';
}
document.getElementById("No4").onclick = function () {
document.getElementById("Question4").style.display = 'None';
document.getElementById("Question10").style.display = 'inline';
}
document.getElementById("Yes5").onclick = function () {
document.getElementById("Question5").style.display = 'None';
document.getElementById("Question10").style.display = 'inline';
}
document.getElementById("No5").onclick = function () {
document.getElementById("Question5").style.display = 'None';
document.getElementById("Question10").style.display = 'inline';
}
document.getElementById("Yes6").onclick = function () {
document.getElementById("Question6").style.display = 'None';
document.getElementById("Question7").style.display = 'inline';
}
document.getElementById("No6").onclick = function () {
document.getElementById("Question6").style.display = 'None';
document.getElementById("Question8").style.display = 'inline';
}
document.getElementById("Yes7").onclick = function () {
document.getElementById("Question7").style.display = 'None';
document.getElementById("Question9").style.display = 'inline';
}
document.getElementById("No7").onclick = function () {
document.getElementById("Question7").style.display = 'None';
document.getElementById("Question9").style.display = 'inline';
}
document.getElementById("Yes8").onclick = function () {
document.getElementById("Question8").style.display = 'None';
document.getElementById("Question9").style.display = 'inline';
}
document.getElementById("No8").onclick = function () {
document.getElementById("Question8").style.display = 'None';
document.getElementById("Question9").style.display = 'inline';
}
document.getElementById("No9").onclick = function () {
document.getElementById("Question9").style.display = 'None';
document.getElementById("Question10").style.display = 'inline';
}
document.getElementById("No9").onclick = function () {
document.getElementById("Question9").style.display = 'None';
document.getElementById("Question10").style.display = 'inline';
}
}
</script>
<body>
<section>
<article>
<hgroup>
<h1>Dynamic Questionnaire</h1>
<h2>Question disappear after clicked</h2>
</hgroup>
<div id="Test1" >
1.1. ...
<input type='radio' id='Yes1' name='answer1'> Yes
<input type='radio' id='No1' name='answer1'> No
</div>
<div id="Test2" >
1.2. ...
<input type='radio' id='Yes1' name='answer1'> Yes
<input type='radio' id='No1' name='answer1'> No
</div>
<div id="Question1">
1. ....
<input type='radio' id='Yes1' name='answer1'> Yes
<input type='radio' id='No1' name='answer1'> No
</div>
<div id="Question2" style='display:none' >
2. ....
<input type='radio' id='Yes2' name='answer1'> Yes
<input type='radio' id='No2' name='answer1'> No
</div>
<div id="Question3" style='display: none'>
3. ....
<input type='radio' id='Yes3' name='answer1'> Yes
<input type='radio' id='No3' name='answer1'> No
</div>
<div id="Question4" style='display: none'>
4. ....
<input type='radio' id='Yes4' name='answer1'> Yes
<input type='radio' id='No4' name='answer1'> No
</div>
<div id="Question5" style='display: none'>
5. ....
<input type='radio' id='Yes5' name='answer1'> Yes
<input type='radio' id='No5' name='answer1'> No
</div>
<div id="Question6" style='display: none'>
6. ....
<input type='radio' id='Yes6' name='answer1'> Yes
<input type='radio' id='No6' name='answer1'> No
</div>
<div id="Question7" style='display: none'>
7. ....
<input type='radio' id='Yes7' name='answer1'> Yes
<input type='radio' id='No7' name='answer1'> No
</div>
<div id="Question8" style='display: none'>
8. ....
<input type='radio' id='Yes8' name='answer1'> Yes
<input type='radio' id='No8' name='answer1'> No
</div>
<div id="Question9" style='display: none'>
9. ....
<input type='radio' id='Yes9' name='answer1'> Yes
<input type='radio' id='No9' name='answer1'> No
</div>
<div id="Question10" style='display: none'>
10. ....
<input type='radio' id='Yes10' name='answer1'> Yes
<input type='radio' id='No10' name='answer1'> No
</div>
</article>
</section>
</body>
</html>
[Sorry if i pasted too much code, can still barely use StackOverflow] So, when i run my html file, when the first Question appears, it has 'yes' and 'no' radio buttons.And when i click yes it should go to question 2 but hide question 1. And if i click no, it should hide question 1 as well but go to question 3. PS: I removed some html tags