highlight td border when checkbox event is fired

Discussion in 'JavaScript' started by barnes, Apr 9, 2007.

  1. #1
    A table consist 4 trs,in each tr we have 2 tds in each td i am putting templates as a image.below of each image we have one check box.when i clicking on a checkbox.i want to highlight the perticular td(image) border..
    any help....
     
    barnes, Apr 9, 2007 IP
  2. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Barnes,
    instead of trying to put a border on a TD, why not put a border on the image? I believe you will have an easier time doing it that way. Example:

    <style>
    .imgNotchecked { border:0px;}
    .imgChecked {border:1px solid red;}
    </style>

    <img class='imgNotchecked' id='image001' src='yada.jpg' width='100' height='75'>

    <input type='checkbox' onclick="if (this.checked) { document.getElementById('image001').className='imgChecked';}">
     
    datropics, Apr 9, 2007 IP
  3. barnes

    barnes Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    many thanks good advice datropics..
     
    barnes, Apr 9, 2007 IP
  4. barnes

    barnes Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    one more thing..how to get deactivate the image border if we deselecting checkbox....
     
    barnes, Apr 9, 2007 IP
  5. barnes

    barnes Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i got it.i modified like this..
    <style type="text/css">
    .imgNotchecked { border:0px;}
    .imgChecked {border:1px solid red;}
    </style>

    <img class='imgNotchecked' id='image001' src='custom-gifts-banner.jpg' width='100' height='75'>
    <form name="frmAddress">
    <input type="checkbox" name='address' onclick="javascript:activate()">
    </form>
    <script language="javascript">
    function activate()
    {
    if(document.frmAddress.address.checked == true)
    {
    document.getElementById('image001').className='imgChecked';
    }
    else
    {
    document.getElementById('image001').className='imgNOtChecked';
    }
    }
    </script>
     
    barnes, Apr 9, 2007 IP
  6. barnes

    barnes Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    is it possible with out form tag.if possible please help me..
     
    barnes, Apr 9, 2007 IP
  7. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #7
    Sure!
    <input type="checbox" name="address" id="address" onclick="javascript:activate(this.id,'image001');">

    <script ...>
    function activate(who,whichimage)
    {
    document.getElemtnById(whichimage).className = (document.getElementById(who).checked == true) ? 'imgNotChecked' : 'imgChecked';
    }
    </script>

    Doing it this way - you don't need to edit the function itself at all and you can then call it multiple times.

    Hope this Helps
     
    datropics, Apr 10, 2007 IP
  8. barnes

    barnes Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    <style type="text/css">
    .imgNotchecked { border:0px;}
    .imgChecked {border:1px solid red;}
    </style>

    <img class='imgNotchecked' id='image001' src="happybirthday_image.jpg" width='100' height='75'>
    <input type="checkbox" name="address" id="address" onclick="javascript:activate(this.id,'image001');">


    <script language="javascript">

    function activate(who,whichimage)
    {
    document.getElemtnById(whichimage).className = (document.getElementById(who).checked == true) ? 'imgChecked'

    :'imgNotChecked' ;
    }
    </script>
    i didn't get the result through this code.event is not working yaar..
     
    barnes, Apr 10, 2007 IP
  9. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #9
    HA HA HA HA HA HA HA HA HA

    I had spelt incorrectly!

    Original:

    document.getElemtnById(whichimage).className = (document.getElementById(who).checked == true) ? 'imgChecked' : 'imgNotChecked'


    What it should be:

    document.getElementById(whichimage).className = (document.getElementById(who).checked == true) ? 'imgChecked' : 'imgNotChecked';
     
    datropics, Apr 11, 2007 IP
  10. barnes

    barnes Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    many many thanks datropics..may i know about you..you are from ?
     
    barnes, Apr 11, 2007 IP
  11. barnes

    barnes Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    actually i am working on search engine optimization.i know basics of programming languages.i am in learning stage.ur website is looking good.but ur using frame.that's negative impression for ur site according to seo.it's only suggestion.
    r u from westindies..
     
    barnes, Apr 11, 2007 IP
  12. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #12
    LOL HAHAHAHAHAH

    I am not using frames but rather CSS - but glad to see you checked my site - I need to update it though

    Glad you got through with your project. If there are any others you need assistance on let me know
     
    datropics, Apr 11, 2007 IP