ThePagan ThePagan - 3 months ago 13
HTML Question

HTML radio buttons allowing multiple selections

I have a probably a really simple answer to a question but I just can't see where this is going wrong.

In my HTML form I have the below as a set of radio buttons, depending on what radio button you select depends on what the next form

<fieldset>
is revealed, this all works. the problem is for some reason they are working like a check box and not as a radio button.

So you can select all options and not just the one at a time. Can anyone see where this is going wrong in the code below, I've checked other examples online and can't see how mine differs.

Many thanks

<fieldset>
<legend>Please select one of the following</legend>
<input type="radio" name="track" id="track" value="track" /><label for="track">Track Submission</label><br />
<input type="radio" name="event" id="event" value="event" /><label for="event">Events and Artist booking</label><br />
<input type="radio" name="message" id="message" value="message" /><label for="message">Message us</label><br />
</fieldset>

Answer

They all need to have the same name attribute.

The radio buttons are grouped by the name attribute. Here's an example:

<fieldset>
    <legend>Please select one of the following</legend>
    <input type="radio" name="action" id="track" value="track" /><label for="track">Track Submission</label><br />
    <input type="radio" name="action" id="event" value="event"  /><label for="event">Events and Artist booking</label><br />
    <input type="radio" name="action" id="message" value="message" /><label for="message">Message us</label><br />
</fieldset>