Javascript: Change li class if checkbox is selected (on load)

Posted by BoDiE2003 on Stack Overflow See other posts from Stack Overflow or by BoDiE2003
Published on 2010-05-12T13:33:50Z Indexed on 2010/05/12 13:44 UTC
Read the original article Hit count: 210

Filed under:
|
|
|

I have this code on javascript side:

function changeSelectionStyle(id) {
    if(document.getElementById(id).className != 'yes'){
    document.getElementById(id).className = 'yes';
    }
    else{document.getElementById(id).className = '';}
}

And this on html:

    <ul>
      <li id="selectedAuthorities-4_1li" class="">
        <input type="checkbox" id="selectedAuthorities-4_1" name="selectedAuthorities" value="ROLE_ADD_COMMENT_TO_CV" checked="checked" onload="changeSelectionStyle(this.id + 'li');" onclick="changeSelectionStyle(this.id + 'li'); checkFatherSelection(this.id);">

        <a href="#" onclick="document.getElementById('selectedAuthorities-4_1').click(); return false;">  Agregar comentario <samp><b></b>Permite agregar comentario en el detalle.</samp>
        </a>
     </li> 
  </ul>

Well what I cant get work is when the checkbox is selected, on load, the JS should check it, and assign class="yes" to the li, here: <li id="selectedAuthorities-4_1li" class="">

Any suggestions? Thank you

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about checkbox