I am a beginner JavaScript programmer trying to make an html data collecting form with JavaScript.
My goal is to …
I am unsure of then after asking the initial age question, of how to only ask certain questions depending on the user's response to this first.
Here is my code:
<html>
<head>
</head>
<body>
<form>
<label for="age">Select your age</label>
<select id="age">
<option value="0">Under 18</option>
<option value="1">18-60</option>
<option value="2">60+</option>
</select>
<button id="next">Next Question</button>
<!--<select id="subject">
<option value="0">Math</option>
<option value="1">English</option>
<option value="2">Science</option>
<option value="3">History</option>
<option value="4">Geography</option>
<option value="5">Technology</option>
<option value="6">Art</option>
<option value="7">PE</option>
<option value="8">Other</option>
</select>
</form-->
<script>
const next = document.querySelector('#next');
const sb = document.querySelector('#age')
next.onclick = (event) => {
event.preventDefault();
// show the selected index
alert(sb.selectedIndex);
};
//if (sb.selectedIndex == 0) {
//}
</script>
</body>
</html>