37 users online (0 members and 37 guests)  


  Results 1 to 4 of 4

Related

  1. Replies: 6
  2. checkbox madness    Forum: ASP Forum
    Replies: 1
  3. checkbox madness    Forum: HTML Forum
    Replies: 0
  4. No footer and checkbox    Forum: PHP Forum
    Replies: 5
  5. Problem in checkbox [PHP]    Forum: PHP Forum
    Replies: 4
  1. #1
    pegboy's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Aug 2001
    Location
    Knoxville, TN
    Posts
    76

    javascript checkbox

    i have a checkbox next to an image. i'd like the user to be able to click the image (which is also a link) and have it put a check inside the checkbox.

    i've seen this done before, but can't remember where... anyone know?
    robert koons

  2. #2
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732

    Re: javascript checkbox


    Hi there pegboy,

    have a look at this example, it may suit your requirements...
    Code:
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
           "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <title></title>
    <base href="http://mysite.orange.co.uk/azygous/images/"/>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
    
    <style type="text/css">
    <!--
    #lnk {
        outline:none;
     }
    #pic {
        border:0 solid;
     }
    -->
    </style>
    
    <script type="text/javascript">
    <!--
      var temp=0;
    window.onload=function() {
    document.getElementById('cb').onclick=function() {
    if(temp==0) {
       this.checked=false;
     }
    if(temp==1) {
       this.checked=true;
      }
     }
       document.getElementById('pic').onclick=function() {
       document.getElementById('cb').checked='checked';
       temp=1;
      }
     }
    //-->
    </script>
    
    </head>
    <body>
    
    <div>
    <input id="cb" type="checkbox"/>
    <a id="lnk" href="http://www.google.com" target="_blank"><img id="pic" src="ball_shad.jpg" alt=""/></a>
    </div>
    
    </body>
    </html>

  3. #3
    pegboy's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Aug 2001
    Location
    Knoxville, TN
    Posts
    76

    Re: javascript checkbox

    that does work... how could i modify this so that you can uncheck the box?

    thanks for your help!
    robert koons

  4. #4
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732

    Re: javascript checkbox


    Hi there pegboy,

    do you mean like this...
    Code:
        
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <base href="http://mysite.orange.co.uk/azygous/images/">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <style type="text/css">
    <!--
    #lnk {
        outline:none;
     }
    #pic {
        border:0 solid;
     }
    -->
    </style>
    
    <script type="text/javascript">
    <!--
    window.onload=function() {
    document.getElementById('cb').onclick=function() {
    if(this.checked==true) {
       this.checked=false;
     }
     }
       document.getElementById('lnk').onclick=function() {
        this.target='_blank';
     }
       document.getElementById('pic').onclick=function() {
       document.getElementById('cb').checked='checked';
      }
     }
    //-->
    </script>
    
    </head>
    <body>
    
    <div>
    <input id="cb" type="checkbox"/>
    <a id="lnk" href="http://www.google.com"><img id="pic" src="ball_shad.jpg" alt=""/></a>
    </div>
    
    </body>
    </html>
    Last edited by coothead; 08-30-2006 at 10:09 PM.



Tags for this Thread