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.
ἔρως
ἔρως‒15mo 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.
ἔρως
ἔρως‒15mo 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.
ἔρως
ἔρως‒15mo 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.
ἔρως
ἔρως‒15mo 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.
ἔρως
ἔρως‒15mo ago
ive seen a lot
Will45
Will45OPβ€’15mo ago
hello? please how do i do this?
ἔρως
ἔρως‒15mo ago
instead of using a div, use a fieldset and in javascript, you set or remove the disabled attribute that's literally it
Will45
Will45OPβ€’15mo 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
ἔρως
ἔρως‒15mo ago
but the buttons are inside something, right?
Will45
Will45OPβ€’15mo ago
Yes, inside a div containerπŸ˜…
ἔρως
ἔρως‒15mo ago
yes, and instead of that div, you can use a fieldset oh, and since you're using a fieldset, you could use the <legend> tag to show the question you can style it to look like the div i don't know if there's any usability issues from it, but you can ask in #ui-ux
Will45
Will45OPβ€’15mo ago
Alright, so instead of the button tag, i'll use the Legend tag right?
ἔρως
ἔρως‒15mo ago
no, the button tag stays a button tag
Will45
Will45OPβ€’15mo ago
So label tag inside the Button Tag right?
ἔρως
ἔρως‒15mo ago
i wouldn't put a label tag inside, but if it makes it easier to style, keep it
Will45
Will45OPβ€’15mo ago
i meant "Legend", sorry
ἔρως
ἔρως‒15mo ago
the <legend> tag can't be inside a button but you don't have to use it you can pretend that it is some sort of weird <p> tag with hardcoded styles
Want results from more Discord servers?
Add your server