How to make a Quiz App disable other options after an option is selected?

Hello, i need help with my Javascript quiz app. I need to disable other options after an option is selected. I also need to find a way to make sure that when the "Next" button is clicked, the previously selected options/buttons are deselected. I've tried doing this myself but wasnt able to. I'd appreciate your help. The codepen is given below: https://codepen.io/will-ndaji/pen/zYyNjLJ
22 Replies
Chooβ™šπ•‚π•šπ•Ÿπ•˜
The easiest option is to use radio buttons. You can hide the radio button and style the labels to look exactly the same as how your current buttons look. If you must keep the current HTML as it is, you will need to check the event target and set all other buttons to a deselected state.
ἔρως
ἔρως‒13mo ago
here are a few steps i would do: - instead of buttons, use a radio input - wrap the whole thing in a fieldset - when an input in the fieldset changes, set the fieldset to disabled
Chooβ™šπ•‚π•šπ•Ÿπ•˜
It's not necessary to actually set anything as disabled if you use radio buttons. Just set a different style for checked or unchecked.
ἔρως
ἔρως‒13mo ago
I need to disable other options after an option is selected.
this is part of the requirements
Chooβ™šπ•‚π•šπ•Ÿπ•˜
I believe that comes from not understanding another way to implement this.
ἔρως
ἔρως‒13mo ago
that's a fair interpretation but i believe this is like a "click and lock the answer in, to show if it's right or wrong"
Chooβ™šπ•‚π•šπ•Ÿπ•˜
I think you are right. I didn't notice that the button was for next and not submit.
ἔρως
ἔρως‒13mo ago
yup, and if you click on a button, you see a buggy red/green background on the buttons but, a step at a time but, the simplest way is to just wrap it all in a fieldset and put it as disabled
Chooβ™šπ•‚π•šπ•Ÿπ•˜
It's a bad user experience for any answer to be your final answer. I have never seen a quiz like that before.
ἔρως
ἔρως‒13mo ago
ive seen a lot
Will45
Will45β€’13mo ago
hello? please how do i do this?
ἔρως
ἔρως‒13mo ago
instead of using a div, use a fieldset and in javascript, you set or remove the disabled attribute that's literally it
Will45
Will45β€’13mo ago
oh i didnt use a div though, just buttons, everything seems to be working except the javascript part where i'll have to modify the code to disable the deselected options, while making sure the Red or Green background disappears when the next button is clicked
ἔρως
ἔρως‒13mo ago
but the buttons are inside something, right?
Will45
Will45β€’13mo ago
Yes, inside a div containerπŸ˜…
Want results from more Discord servers?
Add your server