Jump to content

<TD> as checkbox label


xn1

Recommended Posts

As to why it wont work I can't help you. It's just different browsers interpreting things differently.

After some testing, what I can tell is that the following works on Chrome, Firefox4, and IE8:

 

<td><label for="foo"><span style="display:block"><input type="checkbox" id="foo" name="option1" value="opt1">option1<br></span></label></td>

 

Link to comment
Share on other sites

or try this :

 

in case tables is the way you want to go

<style type="text/css">/* external stylesheets ftw */
#monkeys span{
    background:greenyellow;
    padding: 3px 0;
    display:block;
}
</style>

<form action="..." method="post">
<table id="monkeys">
  <tr>
    <td><label for="fname"><span>firstname</span></label></td>
    <td><input type="text" name="firstname" id="fname" /></td>
  </tr>
    <td><label for="lname"><span>lastname</span></label></td>
    <td><input type="text" name="lastname" id="lname" /></td>
</table>
</form>

Link to comment
Share on other sites

i changed the css a bit: might looks nicer this way :)

 

 

<style type="text/css">/* external stylesheets ftw */
#monkeys span{
    background:greenyellow;
    padding: 3px 0;
    display:block;
    width:80px;
    text-align: center;
}
</style>

<form action="..." method="post">
<table id="monkeys">
  <tr>
    <td><label for="fname"><span>firstname</span></label></td>
    <td><input type="text" name="firstname" id="fname" /></td>
  </tr>
    <td><label for="lname"><span>lastname</span></label></td>
    <td><input type="text" name="lastname" id="lname" /></td>
</table>
</form>

 

tested in IE 789 opera firefox chrome safari

Link to comment
Share on other sites

The methods mentioned above will actually do that, they allow checking the check box by clicking the cell. This is accomplished with styling of the span element. The reason why we do not put the label tag outside of the cell is exactly because of the reason that it only works in IE that way.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.