Only one value to submitting on form
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="radi开发者_运维百科o" name="attendance" value="No" id="attendance" />
Yes</label>
<label>
<input type="radio" name="attendance" value="Yes" id="attendance" />
No</label>
<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.
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...
You can't have the same id
for two elements. Remove id
or assign different ids
.
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...
I see two mistakes in the code given:
- the label tag should only surround the effective label (not the input tag)
- the two items have the same id, i think that's why you always get the same result
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>
精彩评论