I use a shopify app and want to customize some things that I cant do in the app.
So I have 4 Forms and in the forms are 4-7 input radio buttons
every form is structured like this:
Form 1
<div class="globo-form-control layout-2-column">
<div class="globo-form-input">
<ul class="flex-wrap">
<li class="globo-list-control option-3-column">
<div class="radio-wrapper">
<input class="radio-input" type="radio" />
<label class="radio-label">White</label>
</div>
</li>
<li class="globo-list-control option-3-column">
<div class="radio-wrapper">
<input class="radio-input" type="radio" />
<label class="radio-label">White</label>
</div>
</li>
</ul>
</div>
</div>
Form 2
the same
How can I make that for each Form he can only select one ?
I tried this but this dont work and then he remove all
const rd = document.querySelectorAll('.radio-label');
rd.forEach(e => {
e.addEventListener('click', el => {
rd.forEach(e2 => {
e2.classList.remove('selected-radio');
})
e.classList.add('selected-radio');
});
});
2
Answers
If you just want the radio buttons for each form to be grouped, simply add a
name
attribute to the<input>
field, e.g.,<input class="radio-input" type="radio" name="form1" />
. Radio buttons with the samename
attribute will be grouped together and only one of these grouped buttons can be selected.To ensure that only one radio button can be selected per form, you’ll need to target each set of radio buttons individually within their respective forms. Here’s an example of how you might modify your code: