Reputation: 2649
I have a form with these fields and for some reason attendance only comes through as 'Yes' despite you selecting the 'No' radio button.
Any ideas why and if there is anything wrong with what I have done?
<label>
<input type="radio" name="attendance" value="No" id="attendance" />
Yes</label>
<label>
<input type="radio" name="attendance" value="Yes" id="attendance" />
No</label>
Upvotes: 0
Views: 302
Reputation: 72709
<label>
<input type="radio" name="attendance" value="No" id="attendance" />
No</label>
<label>
<input type="radio" name="attendance" value="Yes" id="attendance" />
Yes</label>
Your label is No
while the value of the radio button is Yes
:)
Also as others have noted: you cannot have two elements with the same id
. You could just use a class
for this.
Upvotes: 2
Reputation: 101
You might differenciate the ID as it should be unique. Also you could use the attribute for
for the label markup.
Like this :
<label for="attendanceyes">
<input type="radio" name="attendance" value="Yes" id="attendanceyes" />
Yes
</label>
<label for="attendanceno">
<input type="radio" name="attendance" value="No" id="attendanceno" />
No
</label>
Upvotes: -1
Reputation: 104
I see two mistakes in the code given:
Upvotes: -1
Reputation: 700720
An id
should be unique, so you should give the elements different identities.
I'm not sure if that is the cause of the problem, but that is the only error in the code that you have shown. If that doesn't help, the problem is in the part of the code that you haven't shown.
As others have mentioned, you have swapped the values and labels betwwen the radio buttons, but that seems to be too obvious...
Upvotes: 0
Reputation: 220126
Use this instead:
<label>
<input type="radio" name="attendance" value="Yes" id="attendance-yes" />
Yes</label>
<label>
<input type="radio" name="attendance" value="No" id="attendance-no" />
No</label>
you had your labels and your values reversed...
Upvotes: 1
Reputation: 12506
You can't have the same id
for two elements. Remove id
or assign different ids
.
Upvotes: 0