www.webdeveloper.com
Results 1 to 4 of 4

Thread: Checkbox not checking

  1. #1
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739

    Checkbox not checking

    I've got a checkbox in an li element. I put an onclick on the li element to toggle the checkbox. This works fine if I am over the li element but not over the checkbox. But if I am over the checkbox the checkbox doesn't change (or it changes twice returning it to the original state). So how do I get this working properly?

    Edit: The code below has all the relevant stuff in it I think, but here's a link to the full online version. The checkboxes are in the fourth tab. http://bokehman.com/UI-test/

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
         "http://www.w3.org/TR/html4/strict.dtd">
    
    <html lang="en">
    <head>
    <meta http-equiv="Content-type" content="text/html;charset=ISO-8859-1">
    <script type="text/javascript">
    onload = layout
    
    function layout()
    {
     LIs = document.getElementById('choose').getElementsByTagName('li')
     for(i=0; i<LIs.length;i++)
     {
      LIs[i].onclick=function(){
       return toggle(this)
      } 
     }
    }
    
    function toggle(caller)
    {
     caller.firstChild.checked = !caller.firstChild.checked
     return false
    }
    </script>
    
    <title></title>
    
    </head>
    
    <body>
    
    <div id="choose">
    <ul>
    <li><input type="checkbox" name="choose[]" value="-1770"> 177.0W NSS 9</li>
    <li><input type="checkbox" name="choose[]" value="-1390"> 139.0W AMC 8</li>
    </ul>
    </div>
    
    </body>
    </html>
    Last edited by bokeh; 04-19-2012 at 02:58 AM.

  2. #2
    Join Date
    Nov 2010
    Posts
    1,086
    forgive the silly question, but isn't this just a very roundabout way of making a label?
    Code:
    <div id="choose">
    <ul>
    <li><input type="checkbox" id="ch1" name="choose[]" value="-1770"/><label for="ch1">177.0W NSS 9</label></li>
    <li><input type="checkbox" id="ch2" name="choose[]" value="-1390"/><label for="ch2">139.0W AMC 8</label></li>
    </ul>
    </div>

  3. #3
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739
    Quote Originally Posted by xelawho View Post
    forgive the silly question, but isn't this just a very roundabout way of making a label?
    Man I suck. When I grow up I want to become a real web developer.

    What about the tabs? Am I missing some glaring shortcut there too? I don't often do coding any more so I'm a bit out of touch.

  4. #4
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,268
    There is no problem with checkboxs without script !

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles