Avatar of willsherwood
willsherwood

asked on 

HTML form label (across table cells)

How to get label scope to extend across table cells?

        <tr>
          <label>
          <td><input name="County" type="checkbox" value="1"  > </td>
          <td>Washington</td>
          </label>
        </tr>

Open in new window

HTML

Avatar of undefined
Last Comment
Designbyonyx
Avatar of Designbyonyx
Designbyonyx
Flag of United States of America image

Use the "for" attribute of the label and an "ed" on the input:

<input id="chkCountry" type="checkbox" value="1" />

<label for="chkCountry">Country</label>
Avatar of Designbyonyx
Designbyonyx
Flag of United States of America image

*id    (not "ed" ;)
SOLUTION
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Designbyonyx
Designbyonyx
Flag of United States of America image

And sorry, I read "County" as "Country".  Here is a full code example:

        <tr>
          <label>
          <td><input name="County" id="chkCounty" type="checkbox" value="1"  > </td>
          <td><label for="chkCounty">Washington</label></td>
          </label>
        </tr>
ASKER CERTIFIED SOLUTION
Avatar of Designbyonyx
Designbyonyx
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of willsherwood
willsherwood

ASKER

<label for>  worked perfectly;
due to inherited formatting, i did need to keep two separate cells.
Avatar of willsherwood
willsherwood

ASKER

thanks all
Avatar of Designbyonyx
Designbyonyx
Flag of United States of America image

Yeah... the following syntax works:

<label><input type="checkbox" value="1" /></label>

Open in new window


But I never use this method mainly because of it's limitation with styling.  You cannot style the input element completely independent of the label element.  For example, what if you want a background on the label only... you can't!  You also can't separate your controls like you were trying to do with the table.  By using the following syntax, I have the greatest amount of flexibility without sacrificing the associative properties of labels -> inputs.

<label for="myCheckbox">My Checkbox</label>
<input type="checkbox" id="myCheckbox" value = "1" />

Open in new window

HTML
HTML

HTML (HyperText Markup Language) is the main markup language for creating web pages and other information to be displayed in a web browser, providing both the structure and content for what is sent from a web server through the use of tags. The current implementation of the HTML specification is HTML5.

62K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo