开发者

How do set my radio buttons to only select one option while also validating XHTML 1.0 Strict?

开发者 https://www.devze.com 2023-02-28 17:48 出处:网络
I have two radio buttons and I would like only one to be selected at a time. The code that I am using works, but I get a warning from the validator saying:

I have two radio buttons and I would like only one to be selected at a time. The code that I am using works, but I get a warning from the validator saying:

Validation Output: 1 Warning

Below is a list of the warning message(s) produced when checking your document. Line 115, Column 26: reference to non-existent ID "addressType"

<td><label for="addressType">Address For</label></td>

This error can be triggered by:

A non-existent input, select or textarea element A missing id attribute A typographical error in the id attribute Try to check the spelling and case of the id you are referring to.

The code that I am using is:

<tr>
<td><label for="addressType">Address For</label></td>
<td><label for="homeType">Home</label>
    <input type="radio" id="homeType" name="addressType" value="home" />
    <label for="busType">Business</label>
    <input type="radio" id="busType" name="addressType" value="business" /></td>
</开发者_Python百科tr>

What am I doing wrong?

Thank you in advance!


As the validation error indicates you should only set <label> elements for items which have an id. That id value should then be set into the for attribute.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号