SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    $books++ == true matsko's Avatar
    Join Date
    Sep 2004
    Location
    Toronto
    Posts
    795
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Checkbox is Checked when text is clicked

    Think about a situation like so...

    <input type="checkbox" /> I agree to the terms of service

    Now when the user clicks on the checkbox it is checked ( or unchecked if already checked ), but when the text is clicked nothing happens ( there is no link or javascript listeners attached to it ).

    So I was wondering, using standard HTML tags, is it possible so that when the text is clicked then the checkbox is checked? Is this possible to do without using javascript?
    I can't believe I ate the whole thing

  2. #2
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HTML Code:
    <input type="checkbox" name="foo" id="foo" /><label for="foo">I agree to the terms of service</label>
    Note: Labels use ids not names. When you click on the text now it should check the box.

  3. #3
    SitePoint Zealot
    Join Date
    May 2006
    Location
    Phoenix, AZ
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah,,

    do <div onclick="document.getElementById('AcceptCheckbox').checked=true">
    Do you accept the terms below?

    Blah blah blah

    </div>
    <input type="checkbox" id="checkbox" />
    Kreative Development
    Infinite Possibilities

  4. #4
    SitePoint Zealot
    Join Date
    May 2006
    Location
    Phoenix, AZ
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry, i didn't read your "no javascript"....to answer ...no
    Kreative Development
    Infinite Possibilities

  5. #5
    $books++ == true matsko's Avatar
    Join Date
    Sep 2004
    Location
    Toronto
    Posts
    795
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah the label is what I was looking for, and the javascript one works fine too. I just hate having to make a listener for such a simple action...

    thanks guys...
    I can't believe I ate the whole thing


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
  •