My goal is to create a dynamic quiz where one question is displayed with multiple radio button options. When a user selects an answer, a new question related to that answer appears below with its set of radio buttons. This process continues for each subsequent answer chosen.
I'm facing an issue where either all selected options remain visible on the page at all times, or only the most recent question stays visible, making it impossible to revisit earlier questions and change answers.
Currently, my code looks like this:
$(document).ready(function(){
$("input[name$='group1']").click(function() {
var test = $(this).val();
$(".desc").hide();
$("#"+test).show();
});
});
.desc { display: none; }
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Basic jQuery Quiz Demo Page</title>
<link rel="Stylesheet" type="text/css" href="styles.css" />
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<h1>Troubleshooting</h1>
<h2>What needs to be fixed?</h2>
<form>
<div><label><input type="radio" name="group1" value="in1">Internet</label></div>
<div><label><input type="radio" name="group1" value="tv1">TV</label></div>
<div><label><input type="radio" name="group1" value="ph1">Phone</label></div>
</form>
<div id="in1" class="desc">
... <!-- Content for Internet Troubleshooting -->
</div>
<div id="in2" class="desc">
... <!-- Additional content based on previous answer in the Internet category -->
</div>
<div id="tv1" class="desc">
... <!-- TV Troubleshooting content -->
</div>
<div id="ph1" class="desc">
... <!-- Phone Troubleshooting content -->
</div>
</body>
</html>