SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru moonman's Avatar
    Join Date
    Dec 2000
    Location
    The Sea of Tranquility
    Posts
    696
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    CheckBox onclick

    Hi,

    I'm having a bit of trouble with what is probably a simple problem.

    I've got a form that has two checkboxes. I need to be able to toggle the checkboxes when clicking on the cell they are in. Also, the two checkboxes are both named "location", and this cannot be changed.

    Thanks

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You can give the checkboxes different ids, and then use the <label> tag:

    HTML Code:
    <input id="first-box" ... > <label for="first-box">select it</label>
    <input id="second-box" ... > <label for="second-box">select it</label>
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    SitePoint Guru moonman's Avatar
    Join Date
    Dec 2000
    Location
    The Sea of Tranquility
    Posts
    696
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not quite what I was after, but I'll remember that for the future.

    The checkbox sits in a table. The cell that contains that table is the one I need to be clickable.

    Thanks

  4. #4
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    UK, London
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nest the checkbox in the label element and give it a display:block and it'll fill the whole cell. Otherwise you can also use JavaScript on the TD, but that is not failsafe and very dirty.

    Code:
    <table>
    <tr>
    <td onclick="var c=this.getElementsByTagName('input')[0];c.checked=c.checked?false:true;"><input type="checkbox"> sdfdsfsdfs</td>
    </tr>
    </table>
    Again: Use label instead, for accessibility's sake.
    Chris Heilmann
    Blog | Articles | Binaries


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •