Radio buttons selected on page load - unwanted

I have a form with a couple of radio buttons. The form is wrapped within a <dialog> element and will be opened only when a button "Back this project" is clicked. When opened, however, the first radio button is always selected and there should be none selected before a user chooses any. Is this default browser behavior or? Also when the form is closed and re-opened, the previous choice is remembered. How can I deselect all radio buttons once the form is re-opened (I know deleting cache is a bad option therefore wouldn't go for that one) Here's my codepen: https://codepen.io/d8701a/pen/bGJKRWO Thanks!
d8701a
CodePen
bGJKRWO
...
7 Replies
Jochem
Jochem9mo ago
it's not checked for me on either firefox or chrome
ἔρως
ἔρως9mo ago
can't reproduce maybe you submitted it once and now it has autocomplete
Jochem
Jochem9mo ago
as for resetting the radiobuttons, you can call .reset() on the form, or you can run through all the input[type="radio"] fields using a loop and querySelectorAll to set checked to false
ἔρως
ἔρως9mo ago
on the close and cancel events of the modal the .reset method is the best choice, btw
Jochem
Jochem9mo ago
only if you don't mind the rest of the form also resetting there's pledge amounts you may want to keep
ἔρως
ἔρως9mo ago
that's a good point
Cyberpunk
CyberpunkOP9mo ago
Thank you all for your help. I decided to go with the .reset() method on the form. I figured that if users were to close the form, they most likely wouldn't mind their pledge amounts reset as well. Again, thanks for quick and helpful answers, I appreciate this! 🙂
Want results from more Discord servers?
Add your server